Dlookup in a macro condition statement

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
Back
Top