J
JamesJ
I'm using the following code to validate (make sure a field has data) new
and existing records at the form level. My Contacts form has a listbox
populated with a select query and I'm only showing the Listing and Phone
data.
The form has all the fields for editing purposes.
In short, I need to check for a value in the ContactTypeID field 3 ways.
1) If the user clicks the Close button
2) If the user clicks a row in the Listbox(lstContacts)
3) If the user selects Close from the custom menu.
This code does work for the On Click of cmdClose and the BeforeUpdate of the
form.
Question. How might I create 1 routine for all 3 conditions? Is there an
easier way to do this?
Private Sub cmdClose_Click()
Dim Response As Integer
If Not IsNull(Me.Listing) And IsNull(Me.ContactTypeID) Then
'data in ContactTypeID is the required
Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")
If Response = vbNo Then
Me.Undo
Me.RecordsetClone.FindFirst ("ContactID = " &
Me!lstContacts) 'This is to sync the selected list box row with the form
Me.Bookmark = Me.RecordsetClone.Bookmark
Call GlobalClose
Else
Me!ContactTypeID.SetFocus
End If
Else
Call GlobalClose
End If
End Sub
Thanks much,
James
and existing records at the form level. My Contacts form has a listbox
populated with a select query and I'm only showing the Listing and Phone
data.
The form has all the fields for editing purposes.
In short, I need to check for a value in the ContactTypeID field 3 ways.
1) If the user clicks the Close button
2) If the user clicks a row in the Listbox(lstContacts)
3) If the user selects Close from the custom menu.
This code does work for the On Click of cmdClose and the BeforeUpdate of the
form.
Question. How might I create 1 routine for all 3 conditions? Is there an
easier way to do this?
Private Sub cmdClose_Click()
Dim Response As Integer
If Not IsNull(Me.Listing) And IsNull(Me.ContactTypeID) Then
'data in ContactTypeID is the required
Response = MsgBox("You failed to enter required data." & vbCrLf & _
"Do you want to continue editing the record?", vbExclamation
+ vbYesNo, _
"Missing Required Data")
If Response = vbNo Then
Me.Undo
Me.RecordsetClone.FindFirst ("ContactID = " &
Me!lstContacts) 'This is to sync the selected list box row with the form
Me.Bookmark = Me.RecordsetClone.Bookmark
Call GlobalClose
Else
Me!ContactTypeID.SetFocus
End If
Else
Call GlobalClose
End If
End Sub
Thanks much,
James