I have a command button (cmdClose) that closes my form OnClick.
I also have a Form_BeforeUpdate that checks to make sure a particular required field has been filled in. If it hasn't, it pops a message box to either set-focus to the field (click YES) or cancel the entire record (click NO).
My problem is with my cmdClose button in conjunction w/ the Form_BeforeUpdate. When cmdClose is clicked, the message box pops up correctly. However, when the YES button is clicked it closes the form anyway, even though it should set focus to the required field.
What's going on? Any help would be greatly appreciated!
sarah
Here's the code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim stdResponse As Integer
' If field not filled out then give the user this message
If IsNull(Me.txtCallerName) Then
stdResponse = MsgBox("You must enter a Caller Name before continuing." _
& vbCr & vbCr & "Do you want to continue?" & vbCr & vbCr & _
"Click YES to finish completing the record, or NO to delete the record.", _
vbYesNo, "Incomplete Record")
' if the user says yes, continue then return them to the field
If stdResponse = vbYes Then
Cancel = True
Me.txtCallerName.SetFocus
Exit Sub
'if they say no, stop the before update and undo the record
Else
Cancel = True
Me.Undo
End If
End If
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate
End Sub
------
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close acForm, "frmPhoneLog", acSaveNo
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub
I also have a Form_BeforeUpdate that checks to make sure a particular required field has been filled in. If it hasn't, it pops a message box to either set-focus to the field (click YES) or cancel the entire record (click NO).
My problem is with my cmdClose button in conjunction w/ the Form_BeforeUpdate. When cmdClose is clicked, the message box pops up correctly. However, when the YES button is clicked it closes the form anyway, even though it should set focus to the required field.
What's going on? Any help would be greatly appreciated!
sarah
Here's the code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Form_BeforeUpdate
Dim stdResponse As Integer
' If field not filled out then give the user this message
If IsNull(Me.txtCallerName) Then
stdResponse = MsgBox("You must enter a Caller Name before continuing." _
& vbCr & vbCr & "Do you want to continue?" & vbCr & vbCr & _
"Click YES to finish completing the record, or NO to delete the record.", _
vbYesNo, "Incomplete Record")
' if the user says yes, continue then return them to the field
If stdResponse = vbYes Then
Cancel = True
Me.txtCallerName.SetFocus
Exit Sub
'if they say no, stop the before update and undo the record
Else
Cancel = True
Me.Undo
End If
End If
Exit_Form_BeforeUpdate:
Exit Sub
Err_Form_BeforeUpdate:
MsgBox Err.Description
Resume Exit_Form_BeforeUpdate
End Sub
------
Private Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
DoCmd.Close acForm, "frmPhoneLog", acSaveNo
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
MsgBox Err.Description
Resume Exit_cmdClose_Click
End Sub