Updating an Access Table

  • Thread starter Thread starter Sheldon
  • Start date Start date
S

Sheldon

I have a form bound to table. Normally when I leave the
record, or the form, the table gets updated. In code, How
do I skip the update beased on a form field value. In
other words, If a particular is null or blank, I don't
want update the record, when exiting the form, or changing
record.

Thanks
 
I have a form bound to table. Normally when I leave the
record, or the form, the table gets updated. In code, How
do I skip the update beased on a form field value. In
other words, If a particular is null or blank, I don't
want update the record, when exiting the form, or changing
record.

Put some VBA code in the Form's BeforeUpdate event; if the record
isn't up to snuff, use MsgBox to inform the user and set the Cancel
argument to True. E.g.

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!txtXYZ & "" = "" Then ' safe test for empty textbox
MsgBox "You must fill in the XYZ textbox"
Me!txtXYZ.SetFocus
Cancel = True
End If
End Sub
 
In the Form's Before Update Event, test for the particular condition, set
Cancel = True, and Undo the changes... the code would be something like
this:

If IsNull(Me!txtAny) = True Or Len(Me!txtNoAny) = 0 Then
Cancel = True
DoCmd.RunCommand acCmdUndo
End If

Larry Linson
Microsoft Access MVP
 
Back
Top