L
lambertsm via AccessMonster.com
I have an exit form button where I just want to confirm with the user if they
want to save or not, if they don’t it closes the form, but if they do it
saves the record before closing. Things have worked great in other forms
with a simple BeforeUpdate event programmed on the form:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intresponse As Integer
intresponse = msgbox("Save changes to this record?", vbYesNo, "Confirm Save")
If intresponse = vbNo Then
Cancel = True
End If
End Sub
But now I have a particular form where I want to do some error checking
before the record is saved so I added an if statement to the BeforeUpdate
event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intresponse As Integer
intresponse = msgbox("Save changes to this record?", vbYesNo, "Confirm Save")
If intresponse = vbNo Then
Cancel = True
Else
'Check the data for errors before saving
If (IsNull(Forms![ProductSKU].Active)) Then
' Warns the user of missing data.
Beep
msgbox "You need to assign an active or inactive status before
saving", vbExclamation, ""
Cancel = True
End If
End If
End Sub
It still works like a charm in that it doesn’t save if the user hasn’t filled
in the active status, but it also closes the form because, of course, they
clicked the exit form button. What I would like to do is give the user an
opportunity to fill in the active status before the form closes on them.
After all, the user did click that they wanted to save the record they just
failed the error check.
I thought about putting the error checking in the exit button but then that
would be annoying for the users who didn’t want to save the record as they
would have to fill in the active status just so they could not save.
Is there a way to get it to abort the code for the exit form button in the
BeforeUpdate code? Or is there a better way to accomplish what I need?
want to save or not, if they don’t it closes the form, but if they do it
saves the record before closing. Things have worked great in other forms
with a simple BeforeUpdate event programmed on the form:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intresponse As Integer
intresponse = msgbox("Save changes to this record?", vbYesNo, "Confirm Save")
If intresponse = vbNo Then
Cancel = True
End If
End Sub
But now I have a particular form where I want to do some error checking
before the record is saved so I added an if statement to the BeforeUpdate
event:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intresponse As Integer
intresponse = msgbox("Save changes to this record?", vbYesNo, "Confirm Save")
If intresponse = vbNo Then
Cancel = True
Else
'Check the data for errors before saving
If (IsNull(Forms![ProductSKU].Active)) Then
' Warns the user of missing data.
Beep
msgbox "You need to assign an active or inactive status before
saving", vbExclamation, ""
Cancel = True
End If
End If
End Sub
It still works like a charm in that it doesn’t save if the user hasn’t filled
in the active status, but it also closes the form because, of course, they
clicked the exit form button. What I would like to do is give the user an
opportunity to fill in the active status before the form closes on them.
After all, the user did click that they wanted to save the record they just
failed the error check.
I thought about putting the error checking in the exit button but then that
would be annoying for the users who didn’t want to save the record as they
would have to fill in the active status just so they could not save.
Is there a way to get it to abort the code for the exit form button in the
BeforeUpdate code? Or is there a better way to accomplish what I need?