Add records using a form

G

Guest

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
 
F

fredg

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

Here's how you can find the correct error and show your own message
for any of the form level errors.

First code the Form's Error event:

MsgBox "Error#: " & DataErr ' Display the error number
Response = acDataErrDisplay ' Display Default message

Then open the form and intentionally make that error.

The message box will display the error number and the default error
message.

Next, go back to the error event and change that code to:

If DataErr = XXXX Then
Response = acDataErrContinue ' Don't display the default message
MsgBox "Please enter data in all required fields."
Else
MsgBox "Error#: " & DataErr
Response = acDataErrDisplay ' Display Default message
End If

where XXXX is the error number.
 
G

Guest

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."
 
G

Guest

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