Runtime error 2467

Jake94

Registered User.
Local time
Today, 10:57
Joined
Dec 28, 2006
Messages
15
Please help! I am getting an error when I run this code as a whole. When I comment either the top or bottom out if works. What am I missing?

Private Sub cmdSubmit_Click()


If Me.cboEmployeeType <> "Managed Resource" Then
DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
End If

If Me.cboEmployeeType = "Managed Resource" Then
If IsNull(Me.txtDateEnd) Then
MsgBox "End Date is a mandatory field"
Me.txtDateEnd.SetFocus
Cancel = False

Else

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close


End If
End If


End Sub
 
First, please use Code tags when posting code (http://www.access-programmers.co.uk/forums/showthread.php?t=240420)

There is no Cancel command for an On_Click event. Try the following:
Code:
Private Sub cmdSubmit_Click()
If Me.cboEmployeeType <> "Managed Resource" Then
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.Close
Else
    If IsNull(Me.txtDateEnd) Then
        MsgBox "End Date is a mandatory field"
        Me.txtDateEnd.SetFocus
    Else
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.Close
    End If
End If
End Sub

Or you could even simplify your code further to this:
Code:
Private Sub cmdSubmit_Click()
If Me.cboEmployeeType = "Managed Resource" And IsNull(Me.txtDateEnd) Then
    MsgBox "End Date is a mandatory field"
    Me.txtDateEnd.SetFocus
    Exit sub
End If

DoCmd.RunCommand acCmdSaveRecord
DoCmd.Close
End Sub
 
TJPoorman, that solved the issue. Thanks for you help!!
 

Users who are viewing this thread

Back
Top Bottom