S
Sprinks
For a timesheet application, I have a command button on a continuous form for
each project record. If the button is pressed, I present a Popup/Modal form
for the user to enter a note related to the project. A button on the 2nd
form closes the form.
Unfortunately, although the BeforeUpdate code below generates the proper
message, the form closes regardless of whether the user selects OK or Cancel.
Can anyone tell me what I'm doing wrong?
Thank you.
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Handler
Dim ctl As Control
Dim intResponse As Integer
For Each ctl In Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl.Value) = 0 Then
intResponse = MsgBox(ctl.name & " is a required field. Please
enter a value or press Cancel to exit without saving record.", vbOKCancel,
"Required Field")
If intResponse = vbOK Then
Cancel = True
ctl.SetFocus
Else
End If
End If
End If
Next ctl
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit
End Sub
each project record. If the button is pressed, I present a Popup/Modal form
for the user to enter a note related to the project. A button on the 2nd
form closes the form.
Unfortunately, although the BeforeUpdate code below generates the proper
message, the form closes regardless of whether the user selects OK or Cancel.
Can anyone tell me what I'm doing wrong?
Thank you.
Private Sub cmdExit_Click()
On Error GoTo Err_cmdExit_Click
DoCmd.Close
Exit_cmdExit_Click:
Exit Sub
Err_cmdExit_Click:
MsgBox Err.Description
Resume Exit_cmdExit_Click
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_Handler
Dim ctl As Control
Dim intResponse As Integer
For Each ctl In Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl.Value) = 0 Then
intResponse = MsgBox(ctl.name & " is a required field. Please
enter a value or press Cancel to exit without saving record.", vbOKCancel,
"Required Field")
If intResponse = vbOK Then
Cancel = True
ctl.SetFocus
Else
End If
End If
End If
Next ctl
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "The following error has occurred. Please contact the system
administrator." & _
vbCrLf & vbCrLf & Err.Number & vbCrLf & Err.Description, vbOKOnly,
"Runtime Error"
Resume Err_Exit
End Sub