How to return the primary key from a combo box

  • Thread starter new2access123 via AccessMonster.com
  • Start date
N

new2access123 via AccessMonster.com

I have a table containing two columns
Column 1: Primary key
Column 2: Name.

I want to create an unbound combo box that shows the name but returns the PK.
I have these properties set:

Control source: <is empty>
Row source type: table/query
Bound column: 1
Row source: <I have a select that returns the desired records>

In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see
the name. I need the PK so I can construct the query for the next combo box.


How do I get the PK

Thanks for the help
 
J

John W. Vinson

I have a table containing two columns
Column 1: Primary key
Column 2: Name.

I want to create an unbound combo box that shows the name but returns the PK.
I have these properties set:

Control source: <is empty>
Row source type: table/query
Bound column: 1
Row source: <I have a select that returns the desired records>

In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see
the name. I need the PK so I can construct the query for the next combo box.

You need ColumnCount = 2, Bound Column 1, ColumnWidths property

0";1"

(or some other nonzero width for the name).
 
N

new2access123 via AccessMonster.com

I have these propeerties set...
row source : SELECT Client.Name FROM Client ORDER BY [Name];
ColumnCount: 2
Bound Column: 1
ColumnWidths: 0";2"

In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see
the still see the name from column 2 not the PK from column 1.

Is there something I am missing?

I have a table containing two columns
Column 1: Primary key
[quoted text clipped - 10 lines]
In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see
the name. I need the PK so I can construct the query for the next combo box.

You need ColumnCount = 2, Bound Column 1, ColumnWidths property

0";1"

(or some other nonzero width for the name).
 
N

new2access123 via AccessMonster.com

I see my error. Left out the PK from the SELECT field list. Thank ypu for
the help.

I have these propeerties set...
row source : SELECT Client.Name FROM Client ORDER BY [Name];
ColumnCount: 2
Bound Column: 1
ColumnWidths: 0";2"

In cboClient_AfterUpdate() I look at debug.print cboClient.Value and I see
the still see the name from column 2 not the PK from column 1.

Is there something I am missing?
[quoted text clipped - 7 lines]
(or some other nonzero width for the name).
 
J

John W. Vinson

I see my error. Left out the PK from the SELECT field list. Thank ypu for
the help.

<g> Yep... can't save what isn't there! Glad you got it working.
 

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