Syntax used with DFirst etc

Peter Bellamy

Registered User.
Local time
Today, 21:36
Joined
Dec 3, 2005
Messages
295
I have been trying to write some code which will lookup the first, last and record count the entries in several tables. All the tables have the same structure and naming convention so I hoped to right a 'universal' DFirst/Dlast/Dcount set of statements and just pass the 'names' over as variables

The Table name is set by a button click, eg
tablename = Table1
tableshortname = table

It then jumps to a subroutine which has the DFirst, DLast and Dcount statements.
The problem is that I cannot get the syntax right so reads the Table and field names names correctly.

serial = tableshortname & "_serialno" ' concatanates to table_serialno

Then, for example
firstrec = DFirst("serial", "tablename") Which does not not work !
Which is trying to say :
firstrec = DFirst("[table_serialno]", "Table1")


Any suggestions please?

Cheers
 
Dxxxxx() is looking for string parameters

"literal strings"

...just like that was


or string-variables
dim blah as string
blah = "fubar"

...like the variable blah


sitcking quotes around a string variable is ...unfortunate.
your "serial" will be evaluated as the literal text serial and not the current value of the variable. it's never going to work, and truly wonderful confusion could result if you happen to have a field name [serial] in the table

to answer your question directly, use:

dim serial as string
serial = tableshortname & "_serialno"
firstrec = DFirst(serial, "tablename")

izy
 
Agree with all the above, but think that
izyrider said:
firstrec = DFirst(serial, "tablename")

should be

Code:
firstrec = DFirst(serial, tablename)

based on the OP's description of the problem
 
Thanks for your replies.

Yes indeed leaving off the quotes does work correctly.
I thought I had tried that, but obviously not.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom