Lookup

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?
 
K

Ken Snell

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
 

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