Check to see if a record exist

craigachan

Registered User.
Local time
Today, 02:52
Joined
Nov 9, 2007
Messages
285
I would like help with a macro that looks to see if a record in my database table exists, then if it doesn't it adds a record with my data, but if the records does exist, it stops the routine and sends a message box to prompt if you want to continue with adding a new record.

The problem that I'm having is that my macro errors out when it doesn't find a record. I just want my macro to just see if a record exists or not. Then I can write my Iff statements based on whether it finds our or not. How do I just have my macro check for an record, then if it doesn't exist tell that it doesn't exist and not stop my macro. Is there some kind of IfExist() function or something?

Thanks for any help anyone can give me.
 
Don't use a macro. Just use a DLookup(). It is only a couple of lines of code.

If IsNull(DLookup("fieldName", "table or query name", "criteria string") Then
--- record not found code
Else
--- record found code
End if
 
Thanks so much. I had a mental block for some reason. I'm sure this will solve my problem.
 
Thanks Pat, I still wanted to do it within a macro and it worked very well. I used your Dlookup in the condition field of the macro. It works great. Thanks.
 
If the database is for your own use, feel free to do what you want but if the database is for the use of other people, you need to be a little more professional in your design. Macros do not provide any error handling and therefore do not belong in a finished application.
 

Users who are viewing this thread

Back
Top Bottom