COMBO VALUE TO LIST (1 Viewer)

dubiousp

Member
Local time
Today, 23:47
Joined
Mar 6, 2020
Messages
86
I have list box that I would like to populate from a text box

Private Sub cbmedsearc_AfterUpdate()

Med_Name.AddItem (cbmedsearc.Value)

tried all sorts of differing routes but all fail
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:47
Joined
Oct 29, 2018
Messages
21,496
Hi. Is your Row Source Type set to Value List?
 

Isaac

Lifelong Learner
Local time
Today, 15:47
Joined
Mar 14, 2017
Messages
8,778
I have list box that I would like to populate from a text box

Private Sub cbmedsearc_AfterUpdate()

Med_Name.AddItem (cbmedsearc.Value)

tried all sorts of differing routes but all fail
Also, is your listbox meant to have just 1 column or multiple?
Remove the parenthesis
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:47
Joined
Sep 21, 2011
Messages
14,361
Also, is your listbox meant to have just 1 column or multiple?
Remove the parenthesis
I tend to use Me for form controls, and it works with or without parenthesis and with or without .Value

Code:
Private Sub txtSearchItem_AfterUpdate()
Me.cboSearchItems.AddItem (Me.txtSearchItem.Value)
End Sub
 

Isaac

Lifelong Learner
Local time
Today, 15:47
Joined
Mar 14, 2017
Messages
8,778
I tend to use Me for form controls, and it works with or without parenthesis and with or without .Value
Fair enough. "Remove the parenthesis" was a bit of a long shot ... I couldn't remember if they were truly disallowed, as I'm in the habit of never using parenthesis unless they're required: i.e. a Function or a Call keyword.

I was mostly thinking of multi columns and the potential need to use a) AddItem, b) .List(x)=something , etc. etc.
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:47
Joined
Sep 21, 2011
Messages
14,361
I only tried with one column, and made sure the combo was set to Value List.
Personally I see little point on this as, soon as I load the form I have to start all over again, however it was for an education exercise on my part.
 

Isaac

Lifelong Learner
Local time
Today, 15:47
Joined
Mar 14, 2017
Messages
8,778
Personally I see little point on this as, soon as I load the form I have to start all over again
I have found it useful for those occasional situations when for whatever reason the row source isn't going to be table driven and there are a small number of values that can be coded into the form load
 

dubiousp

Member
Local time
Today, 23:47
Joined
Mar 6, 2020
Messages
86
THe text boxt is a look up a data table that contains about 150 different medications so my thought is to start typing in the text box when the medication it appears and can be added to a list of medications that a person is taking
 

dubiousp

Member
Local time
Today, 23:47
Joined
Mar 6, 2020
Messages
86
Me.Med_Name.AddItem (Me.cbmedsearc.Column(1)) this gives invalid use of null error
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 06:47
Joined
May 7, 2009
Messages
19,247
you never answered the question, which is the Key solution.
What is the Row Source Type of the combobox ?(view it property sheet while in design view of your form).

if it is Value List, you need to use the AddItem method of the combo.
if it is Table/Query you need to Insert a record to your table and requery your combo.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 15:47
Joined
Oct 29, 2018
Messages
21,496
Just FYI, this discussion continued on in this other thread.

 

Users who are viewing this thread

Top Bottom