Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Command button help.

Status
Not open for further replies.

zrobinso

MIS
Apr 22, 2001
27
0
0
US
I have the following events on a form. The first one checks to see if one field is checked, the other field must not be null. It prompts correctly, but it allows the user to close the form. I need it to remain open and set focus on [OES] field.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.IDJob) Then
If IsNull(Me.OES1) Then
MsgBox "ID Job Vacancies is checked. You must enter an OES Code.", vbInformation
DoCmd.CancelEvent
DoCmd.GoToControl "OES1"
Exit Sub
End If
End If
End Sub

AND THIS ON MY COMMAND BUTTON TO CLOSE:

Private Sub closefrm_Click()
On Error GoTo Err_closefrm_Click

DoCmd.Close

Exit_closefrm_Click:
Exit Sub

Err_closefrm_Click:
MsgBox Err.Description
Resume Exit_closefrm_Click

End Sub

Thanks,

Z
 
The Cancel argument in the BeforeUpdate event, if set to True, will cancel the Update event.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Not IsNull(Me.IDJob) Then
If IsNull(Me.OES1) Then
MsgBox "ID Job Vacancies is checked. You must enter an OES Code.", vbInformation
Cancel = True
DoCmd.GoToControl "OES1"
Exit Sub
End If
End If
End Sub

"The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top