Combo Box based on 2 columns

pikou

Registered User.
Local time
Today, 10:38
Joined
Jul 20, 2004
Messages
24
Hello everyone,
I have a combo box on a form tha displays information based on 2 columns from a table.What I want the combo to do is to allow the user to select the row he wants and for the field that is bound to the combo box to store the outcome of collumn1 + collumn2 (string values).
Is this at all possible and if so how can I do it cause I can't find a way.
Thanks for all your time and effort :)
 
A combo box has one bound column. It's rowsource can has several columns.

To concantenate two columns in the combo box control, the underlying row source has to be a query with the columns already concantenated.

However, you can concantenate multiple columns of a combo box for some other use, e.g.

On combo Box (cbo) AfterUpdate event

me!txtControlName = me!cbo.column(0) & me!cbo.column(1)

Columns are numbered 0 through n, left to right.
 
Thanks that helped me a lot !!!
Now what I also want to do is to be able to insert a button on the form the will open up a form linking combo box.column(2) with a field on the form that will be opened.
Any thoughts on that one , let's say that both fields are numbers.
Thanks again :)
 
On the button OnClick event, use

dim stLinkCriteria as string

'if numeric argument
stLinkCriteria = "[fieldname]=" & me!cbo.column(2)

'if string argument
'note that chr(34) is a single quote (")
stLinkCriteria = "[fieldname]=" & chr(34) & me!cbo.column(2) & chr(34)

'if date argument
stLinkCriteria = "[fieldname]= #" & me!cbo.column(2) & "#"
'
DoCmd.OpenForm "YourformName", , , stLinkCriteria

The above will filter the new forms Record Source. Different field datatypes require different concantenation methods.

I find it sometimes easier to use chr(34), instead of quotations, when concantenating fields in complex SQL strings.
 

Users who are viewing this thread

Back
Top Bottom