Have any technique to bind ComboBox to 3 fields ?

  • Thread starter Thread starter Albert
  • Start date Start date
A

Albert

Hello all expert,

In my program, I need to bind combobox to 3 fields which combination is a
primary key. I also have to show this combobox in continuous form which made
this problem harder for me to solve. Have any idea ?

TIA,
Albert
 
A combobox can only be bound to a single field. Are the 3 fields in the
continuous form? Try creating a hidden field that combines them, and bind to
that.
 
Thanks for quick help,

Yes, 3 fields are on continuous form. But binding combobox with combination
of 3 fields can help only for show the information. It can not assign the
values back to those 3 fields when I select the required row.

Albert
 
In my program, I need to bind combobox to 3 fields which combination
is a primary key.

Cannot do this directly: a combobox can only bind to a single field. You
can, however, access any column in the combobox using the Columns() array.
Try this:

With cboSomething
strCriterion = "FieldOne = " & .Columns(1) & _
" AND FieldTwo = """ & .Columns(2) & """" & _
" AND FieldThree = " & Format(.Columns(3), "\#yyyy\-mm\-dd\#")

End With
strSomething = DLookup("Something", "Sometable", strCriterion)



Hope that helps


Tim F
 
Tom
This looks interesting, but I am not able to understand it. How does just defining a string (in this case strCriterion) in a ComboBox's With block produce an action? Also, what is then done with the strSomething after its declaration
Thank you
 
Actually, it can, but you have to use VBA code.

In the combobox's AfterUpdate event, you can put code to populate the 3
fields.
 
This looks interesting, but I am not able to understand it. How does
just defining a string (in this case strCriterion) in a ComboBox's
With block produce an action? Also, what is then done with the
strSomething after its declaration?

To answer the second question first (or, rather, not to) -- what happens
with the stuff depends totally on what you want to happen when the user
pick a line from the combo box.

I was assuming you would want a form to open, or a value to appear in
another control or something. In that case, you can use the Columns()
values to build the command you want, whatever that is. I used the
DLookup() as an example, that is all. The criterion string is fed to the
DLookup, and the result of that would be passed to a control, or a message
box or whatever.

So what is it that you want the user to see when choosing a row from the
combo box?

B Wishes


Tim F
 
Back
Top