I've got a casacading combo box with the following code (see below) as the NotInList procedure. The only problem is that it fails to fire on occasions.
The only other code that I think may be contributing to the problem is a 'requery' of the same combo that has been inserted into the OnCurrent form event. i.e. Me.tblSiteAddress_ID.Requery
Private Sub tblSiteAddress_ID_NotInList(NewData As String, Response As Integer)
On Error GoTo tblSiteAddress_ID_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The site address " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Job Costing")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tblSiteAddress([SiteAddress],[CompanyID]) " & _
"VALUES ('" & NewData & "','" & Form_JobCostingForm.tblCompanyName_ID & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new site address has been added to the list." _
, vbInformation, "Job Costing"
Response = acDataErrAdded
Else
MsgBox "Please choose a site address from the list." _
, vbInformation, "Job Costing"
Response = acDataErrContinue
End If
tblSiteAddress_ID_NotInList_Exit:
Exit Sub
tblSiteAddress_ID_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume tblSiteAddress_ID_NotInList_Exit
End Sub
Any ideas?
The only other code that I think may be contributing to the problem is a 'requery' of the same combo that has been inserted into the OnCurrent form event. i.e. Me.tblSiteAddress_ID.Requery
Private Sub tblSiteAddress_ID_NotInList(NewData As String, Response As Integer)
On Error GoTo tblSiteAddress_ID_NotInList_Err
Dim intAnswer As Integer
Dim strSQL As String
intAnswer = MsgBox("The site address " & Chr(34) & NewData & _
Chr(34) & " is not currently listed." & vbCrLf & _
"Would you like to add it to the list now?" _
, vbQuestion + vbYesNo, "Job Costing")
If intAnswer = vbYes Then
strSQL = "INSERT INTO tblSiteAddress([SiteAddress],[CompanyID]) " & _
"VALUES ('" & NewData & "','" & Form_JobCostingForm.tblCompanyName_ID & "');"
DoCmd.SetWarnings False
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
MsgBox "The new site address has been added to the list." _
, vbInformation, "Job Costing"
Response = acDataErrAdded
Else
MsgBox "Please choose a site address from the list." _
, vbInformation, "Job Costing"
Response = acDataErrContinue
End If
tblSiteAddress_ID_NotInList_Exit:
Exit Sub
tblSiteAddress_ID_NotInList_Err:
MsgBox Err.Description, vbCritical, "Error"
Resume tblSiteAddress_ID_NotInList_Exit
End Sub
Any ideas?