B
Brook
good day all,
I am trying to set up my cbobox to allow for the user to add Values to the
following fields: [Company] & [city_state].
the first issue that I am having is that when I add type a new value in my
cbobox I get the pop up " Do you wish to add the entry ... for cbobox"?
I click Yes and get the following error:
Error 3265: Item Not Found in this collection.
Can anyone help? how do I have the option to add city_state field for my new
entry?
Thanks in advance..
Please let me know if you have any questions...
Brook
I changed the properties of the cbobox LimittoList to "yes" and then have
the following code in the "on not in list" event:
Private Sub cbofromcompany_NotInList(NewData As String, Response As
Integer)
Response = Append2Table(Me![cbofromcompany], NewData)
End Sub
I also have the following module code:
----- Begin Code---
Function Append2Table(cbo As ComboBox, NewData As Variant) As Integer
On Error GoTo Err_Append2Table
' Purpose: Append NotInList value to combo's recordset.
' Assumes: ControlSource of combo has the same name as the foreign key
field.
' Return: acDataErrAdded if added, else acDataErrContinue
' Usage: Add this line to the combo's NotInList event procedure:
' Response = Append2Table(Me.MyCombo, NewData)
Dim rst As DAO.Recordset
Dim sMsg As String
Dim vField As Variant ' Name of the field to append to.
Append2Table = acDataErrContinue
vField = cbo.ControlSource
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
Append2Table = acDataErrAdded
End If
End If
Exit_Append2Table:
Set rst = Nothing
Exit Function
Err_Append2Table:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation,
"Append2Table()"
Resume Exit_Append2Table
End Function
------ End Code ----
I am trying to set up my cbobox to allow for the user to add Values to the
following fields: [Company] & [city_state].
the first issue that I am having is that when I add type a new value in my
cbobox I get the pop up " Do you wish to add the entry ... for cbobox"?
I click Yes and get the following error:
Error 3265: Item Not Found in this collection.
Can anyone help? how do I have the option to add city_state field for my new
entry?
Thanks in advance..
Please let me know if you have any questions...
Brook
I changed the properties of the cbobox LimittoList to "yes" and then have
the following code in the "on not in list" event:
Private Sub cbofromcompany_NotInList(NewData As String, Response As
Integer)
Response = Append2Table(Me![cbofromcompany], NewData)
End Sub
I also have the following module code:
----- Begin Code---
Function Append2Table(cbo As ComboBox, NewData As Variant) As Integer
On Error GoTo Err_Append2Table
' Purpose: Append NotInList value to combo's recordset.
' Assumes: ControlSource of combo has the same name as the foreign key
field.
' Return: acDataErrAdded if added, else acDataErrContinue
' Usage: Add this line to the combo's NotInList event procedure:
' Response = Append2Table(Me.MyCombo, NewData)
Dim rst As DAO.Recordset
Dim sMsg As String
Dim vField As Variant ' Name of the field to append to.
Append2Table = acDataErrContinue
vField = cbo.ControlSource
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
Append2Table = acDataErrAdded
End If
End If
Exit_Append2Table:
Set rst = Nothing
Exit Function
Err_Append2Table:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbInformation,
"Append2Table()"
Resume Exit_Append2Table
End Function
------ End Code ----