Connecting Tech Pros Worldwide Forums | Help | Site Map

{SOLVED} combo box user updating 2nd column

Newbie
 
Join Date: Nov 2006
Posts: 3
#1: Nov 13 '06
G'day guys, I have been trying to use a combo box with two columns. In the first column I am listing 10 items from a table, in the second colum I would like the user to enter some data. The first column lists fine but I can't get anything into the second column. Hope you can help.
I'm using XP and Access 97
Thanks

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#2: Nov 13 '06

re: {SOLVED} combo box user updating 2nd column


Quote:

Originally Posted by parkie

G'day guys, I have been trying to use a combo box with two columns. In the first column I am listing 10 items from a table, in the second colum I would like the user to enter some data. The first column lists fine but I can't get anything into the second column. Hope you can help.
I'm using XP and Access 97
Thanks

To add items to a combo box (or a listbox for that matter) you need to do the following.

Assuming you don't want these values saved in a table.
Create a new textbox for entering the data to be added. Lets call it txtNewData.
Create a command button to put the code behind. Lets call it cmdAddData.
You don't give the name of the combobox so I'm calling it Combo2 for now.

Put this code in the On Click event of the command button:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdAddData_Click()
  3. Dim rowSrc As String
  4.  
  5.   rowSrc = Me.Combo2.RowSource
  6.   rowSrc = rowSrc & ";'" & Me.txtNewData & "'"
  7.   Me.Combo2.RowSource = rowSrc
  8.  
  9. End Sub
  10.  
  11.  
This code will add whatever is in txtNewData to the combobox whenever the button is clicked.
Newbie
 
Join Date: Nov 2006
Posts: 3
#3: Nov 13 '06

re: {SOLVED} combo box user updating 2nd column


Quote:

Originally Posted by mmccarthy

To add items to a combo box (or a listbox for that matter) you need to do the following.

Assuming you don't want these values saved in a table.
Create a new textbox for entering the data to be added. Lets call it txtNewData.
Create a command button to put the code behind. Lets call it cmdAddData.
You don't give the name of the combobox so I'm calling it Combo2 for now.

Put this code in the On Click event of the command button:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdAddData_Click()
  3. Dim rowSrc As String
  4.  
  5.   rowSrc = Me.Combo2.RowSource
  6.   rowSrc = rowSrc & ";'" & Me.txtNewData & "'"
  7.   Me.Combo2.RowSource = rowSrc
  8.  
  9. End Sub
  10.  
  11.  
This code will add whatever is in txtNewData to the combobox whenever the button is clicked.

Many Thanks I'll give this a try
Newbie
 
Join Date: Nov 2006
Posts: 3
#4: Nov 14 '06

re: {SOLVED} combo box user updating 2nd column


I tried it and it worked first time, thank you.
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,885
#5: Nov 14 '06

re: {SOLVED} combo box user updating 2nd column


Quote:

Originally Posted by parkie

I tried it and it worked first time, thank you.

No Problem

I'm marking this solved if no one has any objections.
Reply