B
Brian
I have copied some code from an Access help-site to enable a new "Supplier"
to be added to a combo box through a user form without having to go back to
the source table.
The code is :-
Private Sub Supplier_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!Supplier
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
When a new value is added , I get an error message - "Characters found
after end of SQL statement". The help box says to delete anything after the
semi-colon [;]
I assume the SQL statement is the LookUP Select statement in the underlying
table which is :-
SELECT [tbSuppliers].[Supplier ID], [tbSuppliers].[Supplier] FROM
[tbSuppliers] ORDER BY [Supplier];
I can't figure out what the problem is. Any assistance much appreciated.
ps If the control name is a two-parter ie "Supplier Town" what is the
correct format - To enclose in [ ] or " " or join with an underscore?
to be added to a combo box through a user form without having to go back to
the source table.
The code is :-
Private Sub Supplier_NotInList(NewData As String, Response As Integer)
Dim ctl As Control
' Return Control object that points to combo box.
Set ctl = Me!Supplier
' Prompt user to verify they wish to add new value.
If MsgBox("Value is not in list. Add it?", _
vbOKCancel) = vbOK Then
' Set Response argument to indicate that data
' is being added.
Response = acDataErrAdded
' Add string in NewData argument to row source.
ctl.RowSource = ctl.RowSource & ";" & NewData
Else
' If user chooses Cancel, suppress error message
' and undo changes.
Response = acDataErrContinue
ctl.Undo
End If
End Sub
When a new value is added , I get an error message - "Characters found
after end of SQL statement". The help box says to delete anything after the
semi-colon [;]
I assume the SQL statement is the LookUP Select statement in the underlying
table which is :-
SELECT [tbSuppliers].[Supplier ID], [tbSuppliers].[Supplier] FROM
[tbSuppliers] ORDER BY [Supplier];
I can't figure out what the problem is. Any assistance much appreciated.
ps If the control name is a two-parter ie "Supplier Town" what is the
correct format - To enclose in [ ] or " " or join with an underscore?