Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form closes without saving data

Status
Not open for further replies.

cRODEEkrank

Technical User
Dec 5, 2001
41
US
I have a form which is bound to a table. There are fields on the form which can accept only numerical data and have the validation set in the underlying table. However, if the data entered in the form doesn't meet the validation rule, it closes without saving the record to the table. Although I don't want this bad data entering in the table, I would like to give the user a chance to fix the data before the form closes--display an error message or something.

I have code in the form_error event, but the event is never triggered. The form simply exits with no messages and nothing is saved to the table. Can anyone help with this?

Thanks!
Crank
 
Check the forms cycle property and make sure it is set to "all records". Also check that the record type property is set to dynaset.

Secondly, build a before update event. it does not have to do anything it is just something for you to hang a break in your code. Set a break point in that routine, and modify something on the form. Then do a page down. That should trigger an update. if your code breaks, you are getting an update event to fire. Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Hi Robert,

I got the BeforeUpdate event to fire on my form but it seems strange that the form would exit without any error messages to the user. These fields are set to "Required" in the underlying table and I'm curious why this isn't triggering an error.
 

There is no error within the form. It did attempt the update, your tables rules prohibited the update so everything worked exactly as it should; at least from the point of view of Access.

Obviously, you don’t agree, so don’t let Access get away with it. You will need to use the forms unload event since it allows the action to be cancelled. Your code should work something along the following lines:

Private Sub Form_Unload(Cancel As Integer)

On Error GoTo Form_Unload_Error

If Me.Dirty Then
Cancel = True
MsgBox "You cannot close this form until it is completed or cancelled", vbCritical
End If


On Error GoTo 0
Exit Sub

Form_Unload_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Unload of VBA Document Form_MyForm1"
End Sub
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top