Populate combo box selection from list box

FizzyFish

Registered User.
Local time
Today, 11:45
Joined
Jun 16, 2006
Messages
26
I've created an unbound form with a list box and two combo boxes.

The list box is multi-columns and contains the Primary Keys of the two combo boxes row sources. First column in each of the combo boxes is the primary key and has a zero width so they don't show.

So here is the problem, I have written code for the On-Click event of the list box to populate the keys to each of the combo boxes. When I step through the code and I can see that the keys have been assigned to the combo boxes but the column values are not showing. What am I doing wrong? Is it because the form is unbound? I wouldn't think this would matter since I am populating the combo boxes not the form recordsource.

Anyway here is the code. Any insight is greatly appreciated.

Private Sub lstResults_Click()
Me.cboOne.TAG = Me.lstResults.Column(0)
Me.cboOne.SetFocus
Me.cboOne = Me.lstResults.Column(6)
Me.cboTwo.SetFocus
Me.cboTwo = Me.lstResults.Column(7)
Me.txtOne = Me.lstResults.Column(3)
Me.txtSortOrder = Me.lstResults.Column(4)
Me.cboOne.SetFocus
End Sub
 
The list box is multi-columns and contains the Primary Keys of the two combo boxes row sources. First column in each of the combo boxes is the primary key and has a zero width so they don't show.
OK, so you already have the PK values IN the combo box records. And the PK values that are already listed in the combo box records are in the Listboxes too?
When I step through the code and I can see that the keys have been assigned to the combo boxes but the column values are not showing. What am I doing wrong?
Sounds like you are trying to add the PK values to the combo box list again. Why? Got a picture of the dropdowns in the boxes and the listbox?
 
OK, so you already have the PK values IN the combo box records. And the PK values that are already listed in the combo box records are in the Listboxes too?
Yes they are in the listbox in columns 6 and 7.

Sounds like you are trying to add the PK values to the combo box list again. Why? Got a picture of the dropdowns in the boxes and the listbox?
I'm actually trying to force the selection from the listbox to be what is selected in the combo boxes.

I'm attempting to use a generic unbound form to allow users to maintain data. How it works is I pass the ContactID and the type of data being edited to the form public sub "LoadData". From there I format and populate the listbox. The user can then click on items in the listbox and it should populate to the combo boxes and text fields on the form. The user can then edit the values and save it. The save button runs a query that saves it to the database and then requeries the listbox. I guess what I am attempting to do is grab the PK for the combo box and make that the selected item in the combo box. I am trying to do this for both combo boxes individually but just setting the value to the PK does not seem to do it.

I have attached a picture of the form but the combo boxes collapse whenever I try to do a smart capture of them so I can't get a picture of the drop down values for you, but since the PK is column(0) with a column width of 0 you wouldn't see it anyway.

Sorry it's not a very clear picture when I opened it from here, but the size this forum allows seems to impact the sharpness of the picture.
 

Attachments

Okay it's solved!

First thanks ajetrumpet for attempting to help.

I got it working finally. I was very puzzled because I have created many unbound forms that function exactly as this one does, with listboxes and comboboxes and never had any problems with it in the past.

Out of desperation, I went in and started flipping values of properties bck and forth to see if I could find out specifically which one might be causing a problem. Turns out changing the bound columns from 1 to 0, savine the form and then changing it back to 1 caused it to start working as it should. It's a mystery why it wouldn't work to begin with but I guess it is just one of those flaky things that Access decides to do every now and then. :)
 

Users who are viewing this thread

Back
Top Bottom