simple Dlookup problem

J

Jesper F

I have two option groups with 5 buttons. After selecting a
value in both option groups I want the code to look up a
testID in tblTests but I can't get it to work.
The first option group is called "frame1" and the
other "frame2V".

I thought the following would work:
DLookup("[testID]", "tblTests", "[testgrpID]= " &
Me.frame1 & " AND [testIDsort] = " & me.frame2 & "")

Is it a datatype problem with the variables? In the locals
windows the option group values are listed
as "Variant/long".
Thanks for any input.
 
K

Ken Snell

First suggestion:

You state that the second option group is named
frame2V

but you're using frame2 in the DLookup.
 
J

Jesper F

You state that the second option group is named
frame2V
but you're using frame2 in the DLookup.

Sorry that was a typo when writing the message.
It should be:
DLookup("[testID]", "tblTests", "[testgrpID]= " &
Me.frame1 & " AND [testIDsort]= " & Me.frame2)

The expression returns NULL which confuses me.
However, Debug.Print Me.frame1 and Debug.print Me.frame2
return numbers nicely and when I simply use numbers in the
expression it works.
 
F

fredg

I have two option groups with 5 buttons. After selecting a
value in both option groups I want the code to look up a
testID in tblTests but I can't get it to work.
The first option group is called "frame1" and the
other "frame2V".

I thought the following would work:
DLookup("[testID]", "tblTests", "[testgrpID]= " &
Me.frame1 & " AND [testIDsort] = " & me.(frame2 & "")

Is it a datatype problem with the variables? In the locals
windows the option group values are listed
as "Variant/long".
Thanks for any input.

No problem re: datatype.
An Option Group value is a number datatype.

A different name was used (frame2V / frame2 ) and you added quotes at
the end.

DLookup("[testID]", "tblTests", "[testgrpID]= " & Me.frame1 & " AND
[testIDsort] = " & me.frame2V )
 
T

Terry

Could it be that frame1 and frame2 are strings?

string = NZ(DLookup("[testID]", "tblTests", "[testgrpID]= " & Me.frame1 &
""" AND [testIDsort] = """ & me.frame2 & """"),"")
 
K

Ken Snell

When are you running this code? If you're getting Null as the result, then
either
(1) one of the frame objects does not have a value when you run the code
or
(2) there is no record that matches the two options' values.

--

Ken Snell
<MS ACCESS MVP>

Jesper F said:
You state that the second option group is named
frame2V
but you're using frame2 in the DLookup.

Sorry that was a typo when writing the message.
It should be:
DLookup("[testID]", "tblTests", "[testgrpID]= " &
Me.frame1 & " AND [testIDsort]= " & Me.frame2)

The expression returns NULL which confuses me.
However, Debug.Print Me.frame1 and Debug.print Me.frame2
return numbers nicely and when I simply use numbers in the
expression it works.
 
G

Guest

(2) there is no record that matches the two options'
values.

You're right Ken. I had switched the two parameters and
there were not records matching.
Thanks a bunch for your help both of you !
 

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