J
justme
I was having a heck of a time getting my combo box to requery. I tried about
30 suggestions from different posts until I found this one thread from Brian
Bastl that works for me.
But there's one thing I can't figure out:
on my add form, I have a submit button and a cancel button.
If I click the cancel button, I get the "Item not in list" error, which I'm
pretty sure is due to the resuming of the parent form code : Response =
acDataErrAdded 'tell access to requery combo.
I need that code in order to avoid an error message if the user clicks the
submit button, but that code is messing me up if the user clicks cancel. Any
suggestions?
Private Sub cboColorway_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_Form_Load
Dim strMsg As String
strMsg = cboColorway.text & " is not a known Colorway Code. Would you like
to add it?"
Beep
If MsgBox(strMsg, vbYesNo) = vbYes Then
'open form and pass NewData
DoCmd.OpenForm "fmpColorwayAdd", , , , acFormAdd, acDialog,
UCase(cboColorway.text)
'Response = acDataErrContinue
Response = acDataErrAdded 'tell access to requery combo
Else
'cancel event and undo typing
Response = acDataErrContinue
Me.Undo
End If
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox "Error in Sub cboColorway_NotInList in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
Private Sub btnCancel_Click()
'------------------------------------------------------------
' Cancel Submit Comment
' Created by Mari Berg 2006
'------------------------------------------------------------
On Error GoTo Err_btnCancel
Me.Undo
DoCmd.Close acForm, "fmpColorwayAdd"
Exit_btnCancel:
Exit Sub
Err_btnCancel:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_btnCancel
End Sub
Thank you!
30 suggestions from different posts until I found this one thread from Brian
Bastl that works for me.
But there's one thing I can't figure out:
on my add form, I have a submit button and a cancel button.
If I click the cancel button, I get the "Item not in list" error, which I'm
pretty sure is due to the resuming of the parent form code : Response =
acDataErrAdded 'tell access to requery combo.
I need that code in order to avoid an error message if the user clicks the
submit button, but that code is messing me up if the user clicks cancel. Any
suggestions?
Private Sub cboColorway_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_Form_Load
Dim strMsg As String
strMsg = cboColorway.text & " is not a known Colorway Code. Would you like
to add it?"
Beep
If MsgBox(strMsg, vbYesNo) = vbYes Then
'open form and pass NewData
DoCmd.OpenForm "fmpColorwayAdd", , , , acFormAdd, acDialog,
UCase(cboColorway.text)
'Response = acDataErrContinue
Response = acDataErrAdded 'tell access to requery combo
Else
'cancel event and undo typing
Response = acDataErrContinue
Me.Undo
End If
Exit_Form_Load:
Exit Sub
Err_Form_Load:
MsgBox "Error in Sub cboColorway_NotInList in " & Me.Name & " form." & _
vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
Private Sub btnCancel_Click()
'------------------------------------------------------------
' Cancel Submit Comment
' Created by Mari Berg 2006
'------------------------------------------------------------
On Error GoTo Err_btnCancel
Me.Undo
DoCmd.Close acForm, "fmpColorwayAdd"
Exit_btnCancel:
Exit Sub
Err_btnCancel:
MsgBox "Error " & Err.Number & ": " & Err.Description
Resume Exit_btnCancel
End Sub
Thank you!