MichaelPReid
Technical User
I am using the below code in one of my forms. Three of the combo boxes in the form are populated by data from two related datasheets. I am attempting to create the option of adding new data into the associated data sheet if an entry is not already in the databse.
If I break this code down into its indivdual components, each works perfectly. When I combine the three components (Private Sub Source_NotInList, Sub Byline1_NotInList, Sub Byline2_NotInList) into the below expression, it does not function as it should. Where might I be going wrong?
If I break this code down into its indivdual components, each works perfectly. When I combine the three components (Private Sub Source_NotInList, Sub Byline1_NotInList, Sub Byline2_NotInList) into the below expression, it does not function as it should. Where might I be going wrong?
Code:
Private Sub Source_NotInList(NewData As String, Response As Integer)
Dim iAnswer As Integer
iAnswer = MsgBox("Item is not currently in list, adding item", _
vbOKCancel + vbQuestion)
If iAnswer = vbOK Then
Me.Source.Value = NewData
Set db = CurrentDb
Set rst = db.OpenRecordset("Publication Background")
rst.AddNew
rst.Fields("Source") = NewData
rst.Update
Response = acDataErrAdded
End If
End Sub
Private Sub Byline1_NotInList(NewData As String, Response As Integer)
Dim iAnswer As Integer
iAnswer = MsgBox("Item is not currently in list, adding item", _
vbOKCancel + vbQuestion)
If iAnswer = vbOK Then
Me.Source.Value = NewData
Set db = CurrentDb
Set rst = db.OpenRecordset("Reporter Background")
rst.AddNew
rst.Fields("Byline") = NewData
rst.Update
Response = acDataErrAdded
End If
End Sub
Private Sub Byline2_NotInList(NewData As String, Response As Integer)
Dim iAnswer As Integer
iAnswer = MsgBox("Item is not currently in list, adding item", _
vbOKCancel + vbQuestion)
If iAnswer = vbOK Then
Me.Source.Value = NewData
Set db = CurrentDb
Set rst = db.OpenRecordset("Reporter Background")
rst.AddNew
rst.Fields("Byline") = NewData
rst.Update
Response = acDataErrAdded
End If
End Sub