Using Dlookup with Access97

Paul1100

Registered User.
Local time
Today, 08:26
Joined
May 4, 2013
Messages
17
Hi all, I hope someone can help me i have the following code and keep getting an error when running but i can seem to fine the right combinations to make it work. I'm a novice and am lost please help!!

Dim Answer As Variant
Dim Count As Variant
Answer = DLookup("[Security Code]", "AuthorizedUsertoOverRide", ([Security Code] = '" & [Forms].[OverRide Table].[Security Code] & "') And ("[EmployeeNumber]=[Forms].[OverRide Table].[EmployeeNumber]")
If IsNull(Answer) Then
Count = 0
MsgBox "Not Authorized To Override contact System Admin [" & Me.[EmployeeNumber] & "]"
Else
Count = 1
DoCmd.RunSQL "INSERT INTO[OverRide Table]([Product ID],[Employee Number],[Date])Select[Forms].[OverRide Table].[Date],[Forms].[OverRide Table].[Product ID],[Forms].[OverRide Table].[EmployeeNumber]FROM[AuthorizedUsertoOverRide]"
MsgBox "Record Saved [" & Me.[EmployeeNumber] & "]"
End If

Paul
 
Are those supposed to be 2 criteria? If so try:

DLookup("[Security Code]", "AuthorizedUsertoOverRide", "[Security Code] = '" & [Forms].[OverRide Table].[Security Code] & "' And [EmployeeNumber]= " & [Forms].[OverRide Table].[EmployeeNumber])

This has a multi-criteria example:

http://www.mvps.org/access/general/gen0018.htm
 
Try This:
Change:
Code:
And ("[EmployeeNumber]=[Forms].[OverRide Table].[EmployeeNumber]")
To:
Code:
And ("[EmployeeNumber]=" & [Forms].[OverRide Table].[EmployeeNumber])
 
i'm sorry yes this does have 2 set of criteria and i tried what you said but a get a compile error now
 
Bob i tried your suggestion and i get an error 438 object does not support this property or method
 
What's your code now, and where/what is the compile error?
 
Pbaldy the compile error states expected expression and if i hit ok it goes to the ' after security code =
 
Pbaldy i don't understand your statement "did I miss:"
 
Did you miss that I asked you to post your revised code? It's hard to debug what you can't see.
 
oops I'm sorry and thanks for being so understanding here is the revised code
Answer = DLookup("[Security Code]", "AuthorizedUsertoOverRide", [Security Code] = '" & [Forms].[OverRide Table].[Security Code] & '" And [EmployeeNumber]= " & [Forms].[OverRide Table].[EmployeeNumber])
 
I posted that wrong and corrected it right away. It looks like you picked up the pre-edited version. Try what's in post 2.
 
Okay i tried it again an this time i get an error 438 object does not support this property or method!

Here is the revised code:

Answer = DLookup("[Security Code]", "AuthorizedUsertoOverRide", "[Security Code] = '" & [Forms].[OverRide Table].[Security Code] & "' And [EmployeeNumber]= " & [Forms].[OverRide Table].[EmployeeNumber])
 
On that line? Can you post the db here? That looks correct for a text and numeric field.
 
ok i think you want the whole database but i can't upload it my company has some kinda of firewall thing that errors me out. but you are right the empID is numeric and the security code is text
 
Hopefully Bob is still around and has an idea then. That looks correct to my eye, so I'm down to playing with it to find the problem.
 
That looks correct to my eye, so I'm down to playing with it to find the problem.
Me too, really :(. The only thing I can think of is if the data type of one or both the fields is not what we are assuming.
So, Paul1100:
Please open the table (in design view) that holds the two fields "Security Code" and "EmployeeNumber" and tell us the data type setting of each field. While you're there, also check the spelling. I notice that one has a space in the name but the other does not.
 
[Forms].[OverRide Table]

[OverRide Table] is not a Property of the Forms collection.

It should be:-
[Forms]![OverRide Table]

Chris.
 
ChrisO that is it such a small change can a big difference
 

Users who are viewing this thread

Back
Top Bottom