F
Flightdisc
Hi,
I have some code that is used in the On Not In List and allows you to add
data to an existing list. It works great but I would like to modify it so I
can pass data to it from other form controls. The link to original code was
passed to me by John Vinson MVP (god bless him)
http://www.mvps.org/access/forms/frm0015.htm
I currently have four combo controls each with a populated list. I would
like to use the code below in each combo, but it seems like overkill having
four instances of the same code. I thought being able to pass values to it
would be a better approach, but I don't know how to set that up. Thanks in
advance.
Here's the code:
Private Sub txtCompany_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available Name " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to add the new Name to the current list?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Companies, dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Company_Name = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
I have some code that is used in the On Not In List and allows you to add
data to an existing list. It works great but I would like to modify it so I
can pass data to it from other form controls. The link to original code was
passed to me by John Vinson MVP (god bless him)
http://www.mvps.org/access/forms/frm0015.htm
I currently have four combo controls each with a populated list. I would
like to use the code below in each combo, but it seems like overkill having
four instances of the same code. I thought being able to pass values to it
would be a better approach, but I don't know how to set that up. Thanks in
advance.
Here's the code:
Private Sub txtCompany_NotInList(NewData As String, Response As Integer)
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strMsg As String
strMsg = "'" & NewData & "' is not an available Name " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to add the new Name to the current list?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to link or No to re-type
it."
If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new name?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Companies, dbOpenDynaset)
On Error Resume Next
rs.AddNew
rs!Company_Name = NewData
rs.Update
If Err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If
End If
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub