As I enter values, I would like them to be updated to a list to be used in a combobox (1 Viewer)

hijfte

Registered User.
Local time
Yesterday, 18:37
Joined
Mar 19, 2009
Messages
23
I have fields in my form (frmPicture) called Name, City, State, Country, Color, and backgroundColor. Many of these values will be used multiple times, and I don't want to type them out every time. I don't know all the values at the beginning of the project, so can't just create a list. I would like a list to be created as I type these in, which updates the selections for a combobox for each field. Any ideas?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 16:37
Joined
Aug 30, 2003
Messages
36,127
Search here on "notinlist", the event you can use to add new items to a combo's rowsource.
 

jsv2002

Registered User.
Local time
Today, 00:37
Joined
Feb 11, 2009
Messages
240
You could use something like the following in your Not In List event of your combo box:

Dim db As DAO.Database
Dim newrec As DAO.Recordset
Dim strMsg As String

strMsg = "'" & NewData & "' is not an specified First Aid Action " & vbCrLf & vbCrLf
strMsg = strMsg & "Do you want to add this first aid action to Eyes group?"
strMsg = strMsg & vbCrLf & vbCrLf & "Click Yes to add or No to re-type it."

If MsgBox(strMsg, vbQuestion + vbYesNo, "Add new First Aid Action?") = vbNo Then
Response = acDataErrContinue
Else
Set db = CurrentDb
Set newrec = db.OpenRecordset("Your_Table_Name", dbOpenDynaset)
On Error Resume Next
newrec.AddNew
newrec!Description = NewData '<<<<<This is the field name in the table you want to save to.

newrec.Update

If err Then
MsgBox "An error occurred. Please try again."
Response = acDataErrContinue
Else
Response = acDataErrAdded
End If

End If

Set newrec = Nothing
Set db = Nothing

It saves the new value to the field that the combo box displays you would need to amend the message to suit your application.

Good luck. John :)
 
Last edited:

Users who are viewing this thread

Top Bottom