Test for condition

O

owilson

Hi,

Me again. I have two forms, one that adds data to a
table and one that edits the information in the same
table. (Trying to minimize inadvertant edits) The add
form has the following code:

"INSERT INTO BillingTable (DivNo, ItemDesc, CostCode,
BillingAmount, Percentage, JobNum, YearMonth1)" _
& "VALUES (DivNo, ItemDesc, CostCode,
BillingAmount, Jan, JobNum, YearMonth)"

The YearMonth field in the table is set to not allow
duplicates.

If the user tries to edit info in the Ad form, the usual
long winded error message pops up exlaining that the new
data could not be added.

The message is a little disconcerting to the users and I
would like to intercept that message and insert my own
meesage box telling the user what happened in terms they
understand.

Any suggestions?

TIA

Owen
 
W

Wayne Morgan

1) You could check for the duplicate data using DLookup before attempting to
add the record.

2) When you run the SQL use

CurrentDb.Execute strSQL, dbFailOnError

You should be able to trap the error in an error handler in the procedure or
in the form's Error event.
 

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