Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dlookup with variables

Status
Not open for further replies.

breukelen

Technical User
Oct 31, 2001
54
0
0
NL
Goodmorning,

I have the following lookup :
n1normscore = DLookup("[nscore]", "normscoresn", "[nleeftijdcode] = 'a' And [ncode] = 'n1' and [nruwescore] = 29 ")

Which works fine.

Now I want to change 'a'in a stringvar agecode and 29 in a valuevar ruwn1.
I tried several possibilities ,but I can not get it working.
Hope someone can help.
thanks,

Gunter
 
You need

Code:
n1normscore = DLookup("[nscore]", "normscoresn", "[nleeftijdcode] = '" & agecode & "' AND [ncode] = 'n1' AND [nruwescore] = " & ruwn1 )

Each of the variables needs to come out of the "".. .. .. " string so that it is evaluated on its own and the result concatenated into the final string.

The reason this often causes confusion is that if you put the DLookup into a Control's ControlSource property on a Form or Report then the format is different. People who are used to dealing with ControlSource property versions of DLookup often struggle with the VBA variant.


'ope-that'elps.


G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Thanks very much for your kind help.
It worked fine.

best regards ,

Gunter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top