G
Guest
I have tried many of the previous suggestions on this site and still can't
get this to work. I have a combo box that references one table 'A' to select
a facility to enter into the current table 'B', through control source field.
However, if I have a new facility for table 'A' it errors out.
I do have an event for OnNotInList that does prompt for verification on the
add but I can't seem to get pass this with all great examples out there. Do
I need a more specific field reference? Any help would be appreciated.
Here is my code to date:
Private Sub TestAgencyID_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_TestAgencyID_NotInList
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please retype or clear Lab Name."
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("TestAgengies", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs![TestAgengies]![TestingAgency] = NewData
rs.Update
If Err Then
MsgBox "Error occurred, Please Retry"
Response = acDataErrContine
Else
Response = acDataErrAdded
End If
End If
rs.Close
Exit_TestAgencyID_NotInList:
Exit Sub
Err_TestAgencyID_NotInList:
MsgBox Err.Description
GoTo Exit_TestAgencyID_NotInList
rs.Update
End Sub
get this to work. I have a combo box that references one table 'A' to select
a facility to enter into the current table 'B', through control source field.
However, if I have a new facility for table 'A' it errors out.
I do have an event for OnNotInList that does prompt for verification on the
add but I can't seem to get pass this with all great examples out there. Do
I need a more specific field reference? Any help would be appreciated.
Here is my code to date:
Private Sub TestAgencyID_NotInList(NewData As String, Response As Integer)
On Error GoTo Err_TestAgencyID_NotInList
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim Msg As String
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
Response = acDataErrContinue
MsgBox "Please retype or clear Lab Name."
Else
Set db = CurrentDb()
Set rs = db.OpenRecordset("TestAgengies", dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs![TestAgengies]![TestingAgency] = NewData
rs.Update
If Err Then
MsgBox "Error occurred, Please Retry"
Response = acDataErrContine
Else
Response = acDataErrAdded
End If
End If
rs.Close
Exit_TestAgencyID_NotInList:
Exit Sub
Err_TestAgencyID_NotInList:
MsgBox Err.Description
GoTo Exit_TestAgencyID_NotInList
rs.Update
End Sub