Binding vs display value (1 Viewer)

monika_V

New member
Local time
Today, 20:08
Joined
Oct 7, 2021
Messages
9
Hi,

I have a set the Row Source of a combo box to a query which returns three columns - [part], [desc] and [id]. The combo box Control Source is bound to a table column.

I only want to see the [part] and [desc] fields so I've set colums to 2 and set the widths to 3cm and 6cm. I've bound to column 1 so that the [part] is stored in the table.

After making a selection, I can see the [part] displayed in the combo box. How can I get the [desc] ie the second column value to display in the control after I've selected the item in the control as opposed to the first column value?

Thanks
 
You probably need to widen the width of the dropdown to 9cm or more

and clarify the order of fields in your rowsource - if Id is last and you are selecting 2 columns , little point in including it as it won’t be referenced
 
How can I get the [desc] ie the second column value to display in the control after I've selected the item in the control as opposed to the first column value?
The combo when closed displays only the first column. If you want to show more data, change the rowSource query to concatenate the two columns.

Select ID, colA & " - " & colB As Expr1
Order by colA & " - " & colB;

Bind to the first column but make its width = 0, then make the width of the second column wide enough to show most of the concatenated value.
 
Normally you would store the Part ID, and you relate tables by ID fields. What is Part, and what is ID? Which is the PK? If Part is the primary key what is ID used for?

Not sure I would do this, but tested this and it does what you ask. Basically when you enter the combo to pull down you show 2 columns, and when you leave or update you only show one (the second column).

Code:
Private Sub cmboReports_AfterUpdate()
  Show1 Me.cmboReports
End Sub

Private Sub cmboReports_Click()
  Show2 Me.cmboReports
End Sub
Private Sub cmboReports_Enter()
  Show2 Me.cmboReports
End Sub

Private Sub Show2(cmbo As Access.ComboBox)
  cmbo.ColumnWidths = "3cm.;6cm."
End Sub
Private Sub Show1(cmbo As Access.ComboBox)
  cmbo.ColumnWidths = "0cm.;6cm."
End Sub
 

Attachments

many thanks for your help guys :)

I think I have something usable now
 

Users who are viewing this thread

Back
Top Bottom