Have any technique to bind ComboBox to 3 fields ?

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
 
D

Douglas J. Steele

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.
 
A

Albert

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
 
T

Tim Ferguson

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
 
G

George

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
 
D

Douglas J. Steele

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.
 
T

Tim Ferguson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top