close forms

  • Thread starter Thread starter S. Murphy
  • Start date Start date
S

S. Murphy

I have a form which opens in add mode, but if there is no data in a
particular field I don't want the record to save. Currently I am running a
query to check the table for an empty field on close event and then deleting
that record because of the empty field. What I want to happen is that when I
exit without adding a record, is to check that field on my form, not on the
table. Any suggestions
 
S. Murphy said:
I have a form which opens in add mode, but if there is no data in a
particular field I don't want the record to save. Currently I am running a
query to check the table for an empty field on close event and then deleting
that record because of the empty field. What I want to happen is that when I
exit without adding a record, is to check that field on my form, not on the
table. Any suggestions

If you are using bound forms, the record will always be saved and must be
removed (deleted) from the table. The only way that you can stop its
automatic save is to make it a required field in the table or use the Before
Update event of the form to cancel the update and Undo the record.
(aircode):

Sub Form_ BeforeUpdate(Cancel As Integer)

If Len(Me.txtWhatever & vbNullString) = 0 Then
If MsgBox("Do you want to save", vbYesNo, "Save Record") = vbYes Then
Cancel = True
Me.txtWhatever.SetFocus
Else
Me.Undo
End If
End If

End Sub
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 
S. Murphy said:
I have a form which opens in add mode, but if there is no data in a
particular field I don't want the record to save. Currently I am running a
query to check the table for an empty field on close event and then deleting
that record because of the empty field. What I want to happen is that when I
exit without adding a record, is to check that field on my form, not on the
table. Any suggestions

The most reliable method is to make the field required in the table definition.
Then your form will simply not be able to save a record where that field is not
filled in. Alternatively, you could test for missing entries in the form's
BeforeUpdate event. In that event you could display an error and then set
Cancel = True which will cancel the save. The user is then forced to enter a
value or cancel the entire record.
 
Back
Top