Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-01-14
2
Medium Priority
?
784 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 49

Accepted Solution

by:
Dale Fye earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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