Binding vs display value (1 Viewer)

monika_V

New member
Local time
Today, 23:32
Joined
Oct 7, 2021
Messages
4
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
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:32
Joined
Feb 19, 2013
Messages
16,795
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 18:32
Joined
Feb 19, 2002
Messages
44,010
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 18:32
Joined
May 21, 2018
Messages
8,755
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

  • ShowSecondColumn.accdb
    588 KB · Views: 5

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 23:32
Joined
Jul 9, 2003
Messages
16,479
An alternative would be to display the combo content in separate text boxes, see video at time index 2:45


More info here:-

 

Users who are viewing this thread

Top Bottom