Add records using a form

S

Steven

I have a form that I with a RecordSource of Table1 with Fields: Field1,
Field2, Field3, Field4. The Form's Additions is set to Yes. Table1 has an
index set of Field1 + Field2 and Unique set to Yes. In addition, Field 3
cannot be Null. If I add a new record using the form that is a duplicate or
Field3 Null then the system returns an error message. I do not want the
system message to return but I would like to just show my own message and not
show the system message and then also erase the data in the new record the
user was attempting to add. I don't need any specific itemized message
identifying whether the error was a duplicate or caused by Field3 being Null.
I just need a simple message like: "Cannot Add New Record: Either Field1 +
Field2 already exist OR Field3 is null. Please correct and retry."

I have tried this on my own but have been unsuccessful. How is this done?

Thank you for your help,

Steven
 
S

Steven

Thank you for your repsponse. I have one more question.

If a user adds a record and then hits the close form Command Button while
still on the record, the record will be saved if it passes the criteria
test(s) setup in the table or not saved if it fails the test(s).

How would you tell the user in the Close Command Button code that either the
record was or was not saved before the form closes.

Thanks again.

Steven
 
F

fredg

Thank you for your repsponse. I have one more question.

If a user adds a record and then hits the close form Command Button while
still on the record, the record will be saved if it passes the criteria
test(s) setup in the table or not saved if it fails the test(s).

How would you tell the user in the Close Command Button code that either the
record was or was not saved before the form closes.

Thanks again.

Steven

Well, if I understand you correctly, doesn't my previous reply on
generating that form error message tell the user the record wasn't
saved?

"Cannot Add New Record: Either Field1 +
Field2 already exist OR Field3 is null. Please correct and retry."
 
S

Steven

It works if the user attempts to go to a different record but it the user
hits the Command Button with the OnClick EventProcedure with code
DoCmd.Close; it will just close the form and if the new record is ok it will
save it, if not then it will not save the record. But it does not notify the
user of anything.

Thanks for checking back,

Steven
 
F

fredg

It works if the user attempts to go to a different record but it the user
hits the Command Button with the OnClick EventProcedure with code
DoCmd.Close; it will just close the form and if the new record is ok it will
save it, if not then it will not save the record. But it does not notify the
user of anything.

Thanks for checking back,

Steven

You can use the form's Unload event to verify the data, then message
the user. The user can then let the form close or stop the close and
return to data entry by coding Cancel = True.
 

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