Updateing data when closing forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using MS Access 2000
I have a table that has several required fields.
I developed a form to add records to the table.
In addition to the table fields, the form has a form-close button
constructed with the button wizard.
When I enter a record that does not have the required information and close
the form with the “Close Window†(X) button on the tool bar, the appropriate
error message appears telling me that there is missing data. (Just what I
want)
When I use the close button on the form, the form closes with no message and
without adding the record.
How do I give the button on the form the properties it needs to act the same
as the X button on the tool bar?
 
Plus65: The simple way is to use Validation Rules and Validation Texts on
the required fields. This doesn't always catch problems, however. The
better way is to attach an "OnClick" event procedure to the Close button.
Then use If statments to check the data. If the result is false, send the
user back to the field in question. That's it briefly. Hope this is helpful.
 
I'm guessing your close button uses DoCmd>close. It has long been recommended
that the code

If Me.Dirty Then Me.Dirty = False

be inserted before using

DoCmd.Close

to close a form because of a quirk in Access. When DoCmd.Close is used,
Access closes the form regardless of whether a validation rule or required
field rule has been violated! If one of these rules has been violated, Access
will simply dump the record, close the form, and not tell the user that the
record has been dumped!

Using

If Me.Dirty Then Me.Dirty = False

forces Access to attempt to save the record, and if a violation has occurred,
will throw up a warning message allowing correction to be made before closing
the form.
 
Back
Top