Hi John. Let me break down the parts of my expression to show what each
part is
=DLookUp("[txtletter]","[tblComplaintnbr]","[txtYear]=Forms!frmMain!Subform1![txtYear]")
In the table tblComplaintnbr txtletter is a text field and txtYear is a
Long Integer. There is a different letter for each year so that A is 2005,
B is 2006 and so on.
The value of txtyear in the subform is a calculated control with a source
of =Format([txtcd1retd],"yy") where txtcd1retd is a date/time field.
What I'm trying to do is build up a reference number which is made up of
the last 2 digits of the year, the letter corresponding to that year and
then a sequential number (with a formula of
=Nz(DMax("[txtrefnbr]","tblcomplaints"),0)+1)
These relate to complaints received. So a complaint received on 28/02/08
and is the tenth complaint we've received would have a reference number as
08D10 (08 being the last 2 digits from the date, D being the letter for
2008 and 10 being the tenth complaint)
Does this make it clearer?
Thanks for your help
Tony
John W. Vinson said:
Hi John, The text year from the table is a number whereas the text year
on
the subform is YY from >>=Format([txtcd1retd],"yy") Is that where my
problem is?
Probably. The number 2008 is not equal to the text string "08". Access
does
not, of course, treat either of these fields as a year or a date - it's
much
too literal-minded for that!
Your expression
=DLookUp("[txtletter]","[tblComplaintnbr]","[txtYear]=Forms!frmMain!Subform1![txtYear]")
will look up the first value of txtletter that it finds (probably the
first
record in disk storage order, i.e. an unpredictable record) for which the
value of txtYear in the table is equal to 8. My guess is that is not what
you
want! Will there be only one txtletter for each year? Will the year be
stored
as an integer 8, or as 2008?
John W. Vinson [MVP]