Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I write an event procedure to auto add data to a combo box? 1

Status
Not open for further replies.
Sep 10, 2002
150
US
I know I need to use the notinlist command and limit items to only in the list, but what is the event procedure to be used? For example, the table that stores is list is called OS, and the main table is simply called Main. thanx!
 
Here is an example of a NotInList Event Procedure which updates a table with the data from the ComboBox entry. If there are other fields in the table that need to be updated then you will have to either prompt for them or open another form in acDialog mode so that the user can enter the entire record and all of the data for that record.


Dim db As DAO.Database
Dim rs As DAO.Recordset
' 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.
Set db = CurrentDb
Set rs = db.OpenRecordset("OS", dbOpenDynaset)
rs.AddNew
rs("YourFieldName") = NewData
rs.Update
rs.CLOSE
db.CLOSE
Else
' If user chooses Cancel, suppress error message and undo changes.
Response = acDataErrContinue
End If

Please post back if you have further questions.



Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top