bdsii
03-01-2011, 09:27 AM
Hello all, using Access 2007....I have a form for the user to input data. There is a cancel button on the form and I have disabled the Close button to force using the cancel button.
The first two fields for entry are combo boxes for which I have used code to require an entry. The code is below and is basically the same for both combo boxes.
Private Sub OrigIDCombo_Exit(Cancel As Integer)
If Me.OrigIDCombo.ListIndex = -1 Then
MsgBox "Please select Name"
Me.OrigIDCombo.SetFocus
Cancel = True
End If
End Sub
The problem is the cancel button will not work when the user has not selected anything in this combo box. I keep getting the message to select a Name from the combo box. This seems to happen only when the combo boxes have focus.
What adjustments should I make in the code to allow the cancel to work properly even if nothing has been selected in either of the combo boxes ?
Second question - what code works best for the Cancel button to cause the Add Record to end without adding the record, even if a portion of the data has been supplied by the user and then the cancel button is clicked ? I have had a couple of instances where after some data is entered and the cancel button is clicked I still get a record added with the partial data. i think through correct VBA, I could prevent that. Currently I am using the code below for lack of anything better to use
DoCmd.RunCommand acCmdUndo
DoCmd.Close acForm, "frmEntry"
Any advice would be appreciated.
Thanks !
The first two fields for entry are combo boxes for which I have used code to require an entry. The code is below and is basically the same for both combo boxes.
Private Sub OrigIDCombo_Exit(Cancel As Integer)
If Me.OrigIDCombo.ListIndex = -1 Then
MsgBox "Please select Name"
Me.OrigIDCombo.SetFocus
Cancel = True
End If
End Sub
The problem is the cancel button will not work when the user has not selected anything in this combo box. I keep getting the message to select a Name from the combo box. This seems to happen only when the combo boxes have focus.
What adjustments should I make in the code to allow the cancel to work properly even if nothing has been selected in either of the combo boxes ?
Second question - what code works best for the Cancel button to cause the Add Record to end without adding the record, even if a portion of the data has been supplied by the user and then the cancel button is clicked ? I have had a couple of instances where after some data is entered and the cancel button is clicked I still get a record added with the partial data. i think through correct VBA, I could prevent that. Currently I am using the code below for lack of anything better to use
DoCmd.RunCommand acCmdUndo
DoCmd.Close acForm, "frmEntry"
Any advice would be appreciated.
Thanks !