DLookup Two Fields

J

Jani

I've given up. My condition for the macro is below but when I run the macro
there is no message displayed and the balance of the macro does not run. What
I need is that if the OffLedgerDate entered on the form (in text format
yyyymmdd) is found in the DistDate field on the dbo_uTempLabor_All table AND
if DayDots is found in the Corp field on the dbo_uTempLabor_all table, a
message is to be displayed indicating that the data is already entered.

This is the condition and the action is a MsgBox.
[Forms]![frmMain]![OffLedgerDate]=DLookUp("[DistDate]","dbo_uTempLabor_All")
And "DayDots"=DLookUp("[Corp]","dbo_uTempLaborAll")

2nd line of macro has an Action of Stop Macro.

Any help would be very much appreciated. Thank you!
 
S

Steve Schapel

Jani,

DLookup("[DistDate]","dbo_uTempLabor_All") will return the value of the
DistDate field in the first record of the table. If you want to know if it
is in *any* record in the table, then DLookup is probably the wrong
function. If I undertstand you correctly, I think this should work:
DCount("*","dbo_uTempLabor_All","[DistDate]='" & [OffLedgerDate] & "'")

As for the other bit, I'm not sure I understand. You mean the literal text
"DayDots"? And you want to test whether this appears in the Corp field in
*any* record in the table?
 
J

Jani

Thanks for the super quick response. I need to know if any record in the
dbo_uTempLabor_All table has the in the DistDate field the same date as in
the OffLedgerDate field on the form and also has "DayDots" in the same record
in the Corp field. Am I making myself clear???

Steve Schapel said:
Jani,

DLookup("[DistDate]","dbo_uTempLabor_All") will return the value of the
DistDate field in the first record of the table. If you want to know if it
is in *any* record in the table, then DLookup is probably the wrong
function. If I undertstand you correctly, I think this should work:
DCount("*","dbo_uTempLabor_All","[DistDate]='" & [OffLedgerDate] & "'")

As for the other bit, I'm not sure I understand. You mean the literal text
"DayDots"? And you want to test whether this appears in the Corp field in
*any* record in the table?

--
Steve Schapel, Microsoft Access MVP

Jani said:
I've given up. My condition for the macro is below but when I run the
macro
there is no message displayed and the balance of the macro does not run.
What
I need is that if the OffLedgerDate entered on the form (in text format
yyyymmdd) is found in the DistDate field on the dbo_uTempLabor_All table
AND
if DayDots is found in the Corp field on the dbo_uTempLabor_all table, a
message is to be displayed indicating that the data is already entered.

This is the condition and the action is a MsgBox.
[Forms]![frmMain]![OffLedgerDate]=DLookUp("[DistDate]","dbo_uTempLabor_All")
And "DayDots"=DLookUp("[Corp]","dbo_uTempLaborAll")

2nd line of macro has an Action of Stop Macro.

Any help would be very much appreciated. Thank you!
 
S

Steve Schapel

Jani,

Ok, try it like this:
DCount("*","dbo_uTempLabor_All","[DistDate]='" & [OffLedgerDate] & "' And
[Corp]='DayDots'")>0

Regards
Steve
 
J

Jani

This worked great! I just needed to add [Forms]![frmMain]! to OffLedgerDate.
Thank you so much. Jani

Steve Schapel said:
Jani,

Ok, try it like this:
DCount("*","dbo_uTempLabor_All","[DistDate]='" & [OffLedgerDate] & "' And
[Corp]='DayDots'")>0

Regards
Steve

--
Steve Schapel, Microsoft Access MVP

Jani said:
Thanks for the super quick response. I need to know if any record in the
dbo_uTempLabor_All table has the in the DistDate field the same date as in
the OffLedgerDate field on the form and also has "DayDots" in the same
record
in the Corp field. Am I making myself clear???
 
S

Steve Schapel

Jani,

Ah, ok. I assumed you were running the macro via an event on the frmMain
form, in which case that would not be required, so I guess the macro is
running from another form.
 

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