Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 29th, 2006, 04:32 PM
Registered User
 
Join Date: May 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using a variable to define a column name

Hi,

If anyone can assist, it would be much appreciated. I am writing a search form that currently has 3 combo boxes. What I am trying to do is use the value of one of the controls as a variable to SELECT a column in a query. I can't seem to make it work. I know that I can pass control information as query criteria, but can I use a variable in a select statement? Is there anyway to use the value from my combo box to retrieve the column with that name?

Thanks,

Tara
 
Old May 30th, 2006, 06:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Yes.

You can make a list of column names that are meaningful to the user by populating the list yourself, or you can use the actual column names using a look up on the table you are querying.

Will you use the primary key to look up the records, or some text value?

How are you using the column? It sounds like you are allowing the user to look for a value in their choice of columns. If that is the case, then your link criteria might look like:

sColumnValue = Me.cboColumn
sOtherValue = Me.cboOtherValue

sLink = "[" & sColumnValue & "] = " & "'" & sOtherValue & "'"

That is how you would do this with a text value. If you were using a numeric value, you would use:

sLink = "[" & sColumnValue & "] = " & sOtherValue

Does this help?



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
Input javascript variable into hyperlink column toddw607 ASP.NET 2.0 Basics 1 April 17th, 2008 10:12 AM
How to define .tld wesleygch JSP Basics 1 April 10th, 2007 07:54 AM
How to replace db column name with Global variable nesrine C# 0 March 5th, 2007 10:06 AM
Can u define difference ? gvcc_neel .NET Framework 2.0 4 October 10th, 2005 04:56 AM
find name and define range for Column qball Excel VBA 4 November 17th, 2004 03:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.