Solved

VB - How to set unbound Combobox Item for two column variables

Posted on 2014-01-14
2
765 Views
Last Modified: 2014-01-14
Hello All,

I have a form which has several unbound comboboxes.

In the VB code I set the rowsource of the various comboboxes.

I also have a listbox of existing records where on that listbox's DblClickEvent I go to the Record and update the various unbound comboboxes with the info from that record.

However, one of the comboboxes could have multiple values if I use only one of the rowsource's fields to select by.  Is there a way to do it with two?

For Example.
One of my comboboxes is cboSelectCounty.
My Rowsource is set in the VB code. When the listbox is double clicked I have the code

Private Sub lstExistingRecs_DblClick(Cancel As Integer)
Dim b as long
b = Me.lstExistingRecs.Column(1) ' CountyCodeID

me.cboselectcounty = b
end sub

Everything above works fine as does what I want it to....

HOWEVER, for combobox [cboSelectBkNbrSubBkNbr] the rowsource is set as

"SELECT CountyCodeID, RecBkTypeID, RecBkNbrID, RecBkNbrSubID, BkNbrWhole, RefBk FROM qrySys_ValidRecBkTypeRecBkNbrBkNbrSubByCounty "

When I double click the Listbox I want the selection in [cboSelectBkNbrSubBkNbr] to be based on:
RecBkNbrID
AND
RecBkNbrSubID

I know I can do the RowSource "WHERE RecBkNbrID=x AND  RecBkNbrSubID=y"
but then the drop down list will only show that one particular line if the user needs to change it.

Is there a way to get that one field selected and showing in the combobox without limiting the list to just that one when I'm using 2 variable?
0
Comment
Question by:wlwebb
2 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39779901
You could modify the RowSource for the combo and concatenate those two fields into a single computed field and make that the first field in the combo box (bound column) and hide it.  something like:

SELECT [RecBnNbrID] & "|" & [RecBnNbrSubID] as Key, CountyCodeID,
RecBkTypeID, RecBkNbrID, RecBkNbrSubID, BkNbrWhole, RefBk
FROM qrySys_ValidRecBkTypeRecBkNbrBkNbrSubByCounty

Then, in the double click event, you would concatenate those values in your list, something like:

me.cboSelectBkNprBusBkNbr = Me.lstExistingRecs.Column(0) & "|" & me.lstExistingRecs.column(1)
0
 

Author Closing Comment

by:wlwebb
ID: 39779966
Uggh... missed that one........  Sometimes you just can't see the forest for all the trees right in front of you.........


Thank you for the Help!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question