Visual Basic DLookup returns null

M

michelle

What have I missed in this question?

The variables highestBoxId and travel are declared.
The database in Access is called Photos and it contains the columns eg.
boxId and travelname
which I know contains data. The table consists of 4 rows whith 4
travelnames so it
can not be moore than 1 hit.

Still, after executing this row, highestBoxId, is null. WHY?

highestBoxId = DLookup("max(boxId)", "Photos", "[travelname] = travel")

I appreciate all help
/Michelle

(e-mail address removed)
 
T

Tom Lake

highestBoxId = DLookup("max(boxId)", "Photos", "[travelname] = travel")

If the field in the Photos table is called boxId then you have to do this:

highestBoxId = DLookup("[boxId]", "Photos", "[travelname] = travel")

Tom Lake
 
D

Douglas J Steele

If you want the maximum, use DMax, not DLookup.

As well, if you're looking for the literal word travel as the value for
travelname, you need to put quotes around it since it's text:

highestBoxId = DMax("boxId", "Photos", "[travelname] = 'travel'")

If travel is the name of a variable that holds the value you want to check,
it needs to be outside of the string (but its value needs to be in quotes):

highestBoxId = DMax("boxId", "Photos", "[travelname] = '" & travel & "'")

Exagerated for clarity, that's

highestBoxId = DMax("boxId", "Photos", "[travelname] = ' " & travel & " ' ")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top