lprice1024
July 13th, 2001, 01:09 PM
Here's my code:
Function Append1Table(cbo As ComboBox, NewData As Variant) As Integer
On Error GoTo Err_Append1Table
' Purpose: Append NotInList value to combo's recordset.
' Return: AcDataErrAdded if added, else acDataErrContinue
' Usage: Add this line to the combo's NotInList event procedure:
' Response = Append1Table(Me.Combo32, NewData)
Dim rst As Recordset
Dim sMsg As String
Dim vField As Variant ' Name of the field to append to.
Append1Table = acDataErrContinue
vField = "Apt"
If Not (IsNull(vField) Or IsNull(NewData)) Then
sMsg = "Do you wish to add the entry " & NewData & " for " & cbo.Name & "?"
If MsgBox(sMsg, vbOKCancel + vbQuestion, "Add new value?") = vbOK Then
Set rst = CurrentDb.OpenRecordset(cbo.RowSource)
rst.AddNew
rst(vField) = NewData
rst.Update
rst.Close
Append1Table = acDataErrAdded
End If
End If
Exit_Append1TAble:
Set rst = Nothing
Exit Function
Err_Append1Table:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation, "Append1Table()"
Resume Exit_Append1TAble
End Function
Question: Is it possible to alter this code so i can use it for various combo boxes within the same database....without having to save it as differently named modules over and over again.
Function Append1Table(cbo As ComboBox, NewData As Variant) As Integer
On Error GoTo Err_Append1Table
' Purpose: Append NotInList value to combo's recordset.
' Return: AcDataErrAdded if added, else acDataErrContinue
' Usage: Add this line to the combo's NotInList event procedure:
' Response = Append1Table(Me.Combo32, NewData)
Dim rst As Recordset
Dim sMsg As String
Dim vField As Variant ' Name of the field to append to.
Append1Table = acDataErrContinue
vField = "Apt"
If Not (IsNull(vField) Or IsNull(NewData)) Then
sMsg = "Do you wish to add the entry " & NewData & " for " & cbo.Name & "?"
If MsgBox(sMsg, vbOKCancel + vbQuestion, "Add new value?") = vbOK Then
Set rst = CurrentDb.OpenRecordset(cbo.RowSource)
rst.AddNew
rst(vField) = NewData
rst.Update
rst.Close
Append1Table = acDataErrAdded
End If
End If
Exit_Append1TAble:
Set rst = Nothing
Exit Function
Err_Append1Table:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation, "Append1Table()"
Resume Exit_Append1TAble
End Function
Question: Is it possible to alter this code so i can use it for various combo boxes within the same database....without having to save it as differently named modules over and over again.