Dlookup in a macro condition statement

M

mfg2529

Does anyone know what the syntax and format should be for using DLOOKUP as a condition in a macro

I am trying to basically run macro1 if the value in tableA exists in tableB .....or run macro2 if the value in tableA DOES NO
exist in table B

I know how to write and use a dlookup when comparing a value from a table to the value entered in a form but I
can't figure out the format to type when comparing data between 2 tables

Am pulling my hair out! Would appreciate any help
Thanks in advance for anyone's help!
 
K

Ken Snell

Try this (using DCount instead) as the Condition statement:

DCount("*", "TableName", "[FieldBeingLookedUp]=" &
Forms!FormName!ControlName) > 0


The above will be true if the value exists in the table. Note that the above
syntax assumes that FieldBeingLookedUp is a non-text format. If it's a text
format, then use this (note the use of ' delimiters on either side of the
control's value):

DCount("*", "TableName", "[FieldBeingLookedUp]='" &
Forms!FormName!ControlName & "'") > 0


--
Ken Snell
<MS ACCESS MVP>


mfg2529 said:
Does anyone know what the syntax and format should be for using DLOOKUP as a condition in a macro?

I am trying to basically run macro1 if the value in tableA exists in
tableB .....or run macro2 if the value in tableA DOES NOT
exist in table B.

I know how to write and use a dlookup when comparing a value from a table
to the value entered in a form but I
 

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

Similar Threads

DLookup Two Fields 5
dlookup 2
Delete using join statement 4
delete Using Join Statement 4
MS Access SQL conditional Append 6
DLookup debacle 4
Strange Macro Issue 0
Using Dlookup for SendObject Emails 6

Top