E
Ed from AZ
(Access 2007)
I have a table of vehicle types, a query based on that table, and a
combobox based on the query. I would like the user to be able to
enter something not in the current list of the combobox, have that
entered into the table, and then have the new entry appear in the
combobox list.
I found the following code in a book to enable adding the entery to
the table:
Private Sub lstVehType_NotInList(NewData As String, Response As
Integer)
If MsgBox("This vehicle type is not in the current list." & vbCrLf &
_
"Do you want to add " & NewData & " to the list of vehicle
types?", _
vbYesNo, "Add New Vehicle Type?") = vbYes Then
DoCmd.RunSQL "INSERT INTO tblVehOnly(VehicleType) VALUES ('" &
_
NewData & "')"
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
The record source for my combobox is:
SELECT tblVehSN.VehID, tblVehSN.VehicleSN
I'm thinking that merely adding the new item to the table is not going
to change the data in the combo because the query wasn't refreshed -
yes? So after adding the new data, I need to re-reun the query and
then refresh the combo - yes? I found the .Refresh method for
controls, so I think I can handle that.
But I'm not quite sure how to handle re-running the query. I looked
up Requery in Help, and it pointed me away from the macro and DoCmd
Requery methods to the VBA method. That looks like it needs ADO and a
Recordset object??
Am I once again doing things the hard way? What objects/methods
should I be looking at?
Ed
I have a table of vehicle types, a query based on that table, and a
combobox based on the query. I would like the user to be able to
enter something not in the current list of the combobox, have that
entered into the table, and then have the new entry appear in the
combobox list.
I found the following code in a book to enable adding the entery to
the table:
Private Sub lstVehType_NotInList(NewData As String, Response As
Integer)
If MsgBox("This vehicle type is not in the current list." & vbCrLf &
_
"Do you want to add " & NewData & " to the list of vehicle
types?", _
vbYesNo, "Add New Vehicle Type?") = vbYes Then
DoCmd.RunSQL "INSERT INTO tblVehOnly(VehicleType) VALUES ('" &
_
NewData & "')"
Response = acDataErrAdded
Else
Response = acDataErrContinue
End If
End Sub
The record source for my combobox is:
SELECT tblVehSN.VehID, tblVehSN.VehicleSN
I'm thinking that merely adding the new item to the table is not going
to change the data in the combo because the query wasn't refreshed -
yes? So after adding the new data, I need to re-reun the query and
then refresh the combo - yes? I found the .Refresh method for
controls, so I think I can handle that.
But I'm not quite sure how to handle re-running the query. I looked
up Requery in Help, and it pointed me away from the macro and DoCmd
Requery methods to the VBA method. That looks like it needs ADO and a
Recordset object??
Am I once again doing things the hard way? What objects/methods
should I be looking at?
Ed