469,326 Members | 1,534 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

How to reference ComboBox Column(1) in query?

Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not
seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;
Nov 12 '05 #1
6 52976
If you are trying to do this from a QueryDef object (Queries Tab) then you
can only get at the value (bound column) of the control.
If you are not using the Tag property of the combobox, you could assign the
needed column to it, instead of creating another control.
example: SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Tag

Mike Storr
www.veraccess.com
"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not
seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;

Nov 12 '05 #2
I tried the hidden textbox workaround (which works), but I need to convert
the number in Me!txtCtlID to Long data type in an Update query:

UPDATE tblProperties SET NewCtlID = CLng(Forms!frmMain!txtCtlID)

but this fails due to data type conversion error...
"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not
seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;

Nov 12 '05 #3
then data conversion error was being caused by something else...

"deko" <dj****@hotmail.com> wrote in message
news:dE*****************@newssvr27.news.prodigy.co m...
I tried the hidden textbox workaround (which works), but I need to convert
the number in Me!txtCtlID to Long data type in an Update query:

UPDATE tblProperties SET NewCtlID = CLng(Forms!frmMain!txtCtlID)

but this fails due to data type conversion error...
"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;


Nov 12 '05 #4
Why is your ID field in Column 1 of the combo. Shouldn't it be in column 0?
"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not
seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;

Nov 12 '05 #5
It really doesn't matter which column you use as the bound one, it just
depends on what you are doing with that value.

Mike Storr
www.veraccess.com
"Robert" <ro**********@nospam-unforgettable.com> wrote in message
news:dH*****************@nwrddc02.gnilink.net...
Why is your ID field in Column 1 of the combo. Shouldn't it be in column 0?

"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;


Nov 12 '05 #6
Sorry I should have included the step of assigning the value to the tag
property first. In the combobox AfterUpdate event, add this..

'x is the column you wish to retrive.
Me!cbxCtlID.Tag = Me!cbxCtlID.Column(x)

Then in your SQL statement use...

SELECT .<add fields to retrive>.. WHERE CtlID = Forms!frmMain!cbxCtlID.Tag;

Hope this makes more sense.

Mike Storr
www.veraccess.com

"Mike Storr" <st******@sympatico.ca> wrote in message
news:jx********************@news20.bellglobal.com. ..
If you are trying to do this from a QueryDef object (Queries Tab) then you
can only get at the value (bound column) of the control.
If you are not using the Tag property of the combobox, you could assign the needed column to it, instead of creating another control.
example: SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Tag

Mike Storr
www.veraccess.com
"deko" <dj****@hotmail.com> wrote in message
news:ng*******************@newssvr27.news.prodigy. com...
Can I reference a column other than the bound column of a ComboBox in a
query?

SELECT ... WHERE CtlID = Forms!frmMain!cbxCtlID.Column(1); (this does not seem to work)

Or must I add a hidden text box on frmMain and use this:

Me.txtCtlID = Forms!frmMain!cbxCtlID.Column(1)

SELECT ... WHERE CtlID = Forms!frmMain!txtCtlID;


Nov 12 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ellen Manning | last post: by
1 post views Thread by Oliver Bleckmann | last post: by
1 post views Thread by oval | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.