Lookup

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I want my macro to prompt the user for the name of a
record. Then, if the record exists, stop the macro. What
is the most efficient way to do this?
 
I am not sure what would be the "name" of a record? Do you mean the value of
a primary key for that record?

Assuming so, you could use a step such as this (watch for word wrap in
newsreader), assuming that your primary key field is a text field:

macMacroName
Condition: DCount("*", "table/query name", "[PrimaryKeyField]='" &
InputBox("Enter the primary key value:") & "'") > 0
Action: StopMacro

If the primary key field is a different format, wrap the InputBox portion
inside a function that will convert the text string that the InputBox
returns into the correct format. For example, assuming that your primary key
field is formatted as Long Integer:

macMacroName
Condition: DCount("*", "table/query name", "[PrimaryKeyField]='" &
CLng(InputBox("Enter the primary key value:")) & "'") > 0
Action: StopMacro
 
Back
Top