472,146 Members | 1,308 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 53905
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
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.