Dlookup for two tables (1 Viewer)

ivonsurf123

Registered User.
Local time
Today, 09:44
Joined
Dec 8, 2017
Messages
69
Hello,

I had this code in different buttons to search record on each table and when does not exist to add the new records on each tables using forms

How can I search two tables at the same time with one single button instead of two button for each table?

Table: tbl_CDS_DRA_Key_Legend

sExists = Nz(DLookup("[ExtractType]", "tbl_CDS_DRA_Key_Legend", "[KeyType]='" & Me.txtART & "' AND [ExtractType]='" & Me.txtExtractType & "' AND [Prefix]='" & Me.txtPrefix & "'"))

Table:tbl_CDS_DRA_Key_Master_Codes

sExist = Nz(DLookup("[Vendor]", "tbl_CDS_DRA_Key_Master_Codes", "[Vendor]='" & Me.txtExtractType & "' AND
Code:
='" & Me.txtCode & "'"))

I was trying to combine but it gave me an error:

sExists = Nz(DLookup("[Vendor]", "tbl_CDS_DRA_Key_Master_Codes", "[Code] = " & DLookup("[Code]", "tbl_CDS_DRA_Key_Legend", "[Code]='" & Me.txtCode & "' And [KeyType]='" & Me.txtART & "' AND [ExtractType]='" & Me.txtExtractType & "' AND [Prefix]='" & Me.txtPrefix & "' AND [Vendor]='" & Me.txtExtractType & "'")))

Please help, thank you:banghead:
 

isladogs

MVP / VIP
Local time
Today, 17:44
Joined
Jan 14, 2017
Messages
18,247
Is sExists a boolean (True/False) variable.
If so, you could run code like this:

If the first condition is false, you don't need to check the 2nd condition

Code:
sExists = Nz(DLookup("[ExtractType]", "tbl_CDS_DRA_Key_Legend", "[KeyType]='" & Me.txtART & "' AND [ExtractType]='" & Me.txtExtractType & "' AND [Prefix]='" & Me.txtPrefix & "'"))

If sExists = True Then
   sExists = Nz(DLookup("[Vendor]", "tbl_CDS_DRA_Key_Master_Codes", "[Vendor]='" & Me.txtExtractType & "' AND [COLOR="Red"][YOURCode][/COLOR]='" & Me.txtCode & "'"))
End If

NOTE: I had to change the part in red from
Code:
 to [YOURCode] as it messed up the site code tag feature
 

ivonsurf123

Registered User.
Local time
Today, 09:44
Joined
Dec 8, 2017
Messages
69
Thank you for your reply, I added to my existing code and It worked perfectly!
 
Last edited:

Users who are viewing this thread

Top Bottom