Multiple Dlooups with one result (1 Viewer)

Sodslaw

Registered User.
Local time
Yesterday, 20:40
Joined
Jun 7, 2017
Messages
81
Hello Guys,
Bit of a newbie so apologies in advance I wish to match 3 results if all 3 are true pop up a single message box appears, using the Dlookup method.

Code:
'If DLookup("Retailer", "OnSite_CoverTrue", "Retailer='" & Me!PURCHASED_FROM & "'") = Me!PURCHASED_FROM Then
'            MsgBox "ONsite Retailer = True"
'    End If
'If DLookup("Brand", "OnSite_CoverTrue", "Brand='" & Me!TV_BRAND & "'") = Me!TV_BRAND Then
'
'            MsgBox "ONsite Brand = True"
'    End If
'If DLookup("Model", "OnSite_CoverTrue", "Model='" & Me!TV_MODEL & "'") = Me!TV_MODEL Then
'
'            MsgBox "ONsite Model = True"

Obviously using this method I get 3 individual pop-ups if all criteria are met. but the goal is to get 1 popup if all 3 are met. please help :)
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:40
Joined
Aug 30, 2003
Messages
36,125
Try

If DLookup(...) And DLookup(...) And DLookup(...) Then
 

Sodslaw

Registered User.
Local time
Yesterday, 20:40
Joined
Jun 7, 2017
Messages
81
Absolutely Brilliant!

That worked a treat thanks!
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:40
Joined
May 21, 2018
Messages
8,527
You could also make a single query that uses
Forms!FormName.PURCHASED_FROM
Forms!FormName.Tv_Brand
Forms!FormName.Tv_Model
as parameters
and do a dcount to see if 1 record is returne
dcount(*,"Myquery") >0
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:40
Joined
May 21, 2018
Messages
8,527
Or you could make a single where clause and see if one returned.
Code:
dim strWhere as string
string where = "Retailer='" & Me!PURCHASED_FROM & "' AND Brand='" & Me!TV_BRAND & "' AND Model='& Me!TV_MODEL & "'"
debug.print 'verify string is correct
if dcount(*,"Onsite_Cover",strwhere) > 0
 

Sodslaw

Registered User.
Local time
Yesterday, 20:40
Joined
Jun 7, 2017
Messages
81
Thanks MajP,
I will try to use the method you described next as I love learning especially new methods using fewer resources and faster results. But, As I'm a bit of an old geezer what life has taught me is that, if it ain't broke, don't fix it. :D

Thanks again guys, what a great forum!
 

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 23:40
Joined
May 21, 2018
Messages
8,527
Sorry for the typo
if dcount(*,"Onsite_Cover",strwhere) > 0
should be
Code:
if dcount("*","Onsite_Cover",strwhere) > 0
Need to make first argument a string. Also if you do the first solution provided
On that note

Code:
If DLookup("Retailer", "OnSite_CoverTrue", "Retailer='" & Me!PURCHASED_FROM & "'") = Me!PURCHASED_FROM
This may be simpler to write and likely more efficient. A few less places to make mistakes.
Code:
If DCount("*", "OnSite_CoverTrue", "Retailer='" & Me!PURCHASED_FROM & "'") > 0
 

Users who are viewing this thread

Top Bottom