473,410 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

QBE: Parameter as field name

Is it possible to use a parameter as the field name, not just a
criteria?

Snippet of my SQL:

SELECT Eval("[Forms]![frm__Setup]![lbo_CurrentFields].[Column](0)") AS
TestField, [TestField] AS [Current Value] from qry_main

The parameter [TestField] will hold the name of the field. In the first
column, I want to show the name of the field for all records. In the
second column, I want to show the actual value of this field for the
current record:

STR_STUDENTID 999999
STR_STUDENTID 999982
STR_STUDENTID 999945

I hope this makes sense. I know that this is probably so simple I'm
looking right at it, but I can't seem to figure this out.

TIA

Apr 18 '06 #1
3 4063
Daron, I don't believe you can do that, but it is very easy to create the
SQL statement in VBA on the fly.

For example, if you a combo box with these properties:
Row Source Type Field List
Row Source Table1
Name cboField
you could write this code:
Dim strSql as String
If Not IsNull(Me.cboField) Then
strSql = "SELECT [" Me.cboField & "] FROM Table1;"
End If

You can then assign this to an existing query:
dbEngine(0)(0).QueryDefs("Query1").SQL = strSql
or a form:
Me.RecordSource = strSql
or to a report (in its Open event.)

It would be possible to use a multi-select list box to select multiple
fields, and then loop through its ItemsSelected collection to build up the
query statement. (These techniques avoid the user choosing invalid field
names.)

Ultimately, though, the disappearing fields will cause problems for any form
or report that has controls bound to those fields, so the question may hint
that the data structure is not relational (e.g. the fields are repeating
names where they should be records in a related table.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Daron" <Da**********@gmail.com> wrote in message
news:11*********************@z34g2000cwc.googlegro ups.com...
Is it possible to use a parameter as the field name, not just a
criteria?

Snippet of my SQL:

SELECT Eval("[Forms]![frm__Setup]![lbo_CurrentFields].[Column](0)") AS
TestField, [TestField] AS [Current Value] from qry_main

The parameter [TestField] will hold the name of the field. In the first
column, I want to show the name of the field for all records. In the
second column, I want to show the actual value of this field for the
current record:

STR_STUDENTID 999999
STR_STUDENTID 999982
STR_STUDENTID 999945

I hope this makes sense. I know that this is probably so simple I'm
looking right at it, but I can't seem to figure this out.

TIA

Apr 19 '06 #2
On 18 Apr 2006 12:05:23 -0700, "Daron" <Da**********@gmail.com> wrote:

No, I don't think so.
Rather use a dynamic sql statement:
dim s as string
s="select " & [Forms]![frm__Setup]![lbo_CurrentFields].[Column](0) & "
from qry_main"
Me.RecordSource = s

-Tom.

Is it possible to use a parameter as the field name, not just a
criteria?

Snippet of my SQL:

SELECT Eval("[Forms]![frm__Setup]![lbo_CurrentFields].[Column](0)") AS
TestField, [TestField] AS [Current Value] from qry_main

The parameter [TestField] will hold the name of the field. In the first
column, I want to show the name of the field for all records. In the
second column, I want to show the actual value of this field for the
current record:

STR_STUDENTID 999999
STR_STUDENTID 999982
STR_STUDENTID 999945

I hope this makes sense. I know that this is probably so simple I'm
looking right at it, but I can't seem to figure this out.

TIA


Apr 19 '06 #3
Allen & Tom,

Thanks, thats what I was afraid of. I'm creating a validation app that
will check text files that we get from a variety of sources, and I am
trying to use a "table of SQL" approach.

I am trying to keep this away from hard-coding the SQL as much as
possible, but I will just have to frefigure parts of my design.

Thanks again!

Apr 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: i. dzhugashvili | last post by:
I'm hoping someone can help me here. I'm having problems using a function to get the search criteria for a column in the QBE grid. The column's data type is Long and the problem is that if I...
3
by: Laurel | last post by:
this is driving me crazy. i need to use a form control as a criteria in a select query, and the control's value is set depending upon what a user selects in an option group on the form. the query...
1
by: Pauline Liu | last post by:
Hi, How do you reference a combo box first column in a query as a parameter? For example, in MyQuery in Name column, I want to put down as a parameter from the first column of a combo box in...
6
by: dixie | last post by:
I am trying to do a simple IIf expression in the QBE for a query parameter. What I am trying to type in is IIf(!! = 0,0,,). What it changes to when I type it in is IIf(!! = 0,0,",") - this then...
3
by: Colleyville Alan | last post by:
I am constructing a SQL command from a function. Some code builds the WHERE clause in a looping structure and passes that as an argument to the SQL-building function. But the results do not...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
4
by: geronimo_me | last post by:
Hi, I have a problem, I have typed the following expression in my QBE window but it keeps erroring: Expr1: IIf(!>37,"N","Y"), IIf(!=37,"N","Y")) Basically, I want to check that if a record...
0
by: siddu | last post by:
Hi All, I know how to create a parameter field and Formulafield. Please tell me How to use parameter field in my Report. I Created one parameter field with name.A window opened which taking...
1
by: Ben | last post by:
NooB: Anyone help with what I could be doing incorrectly here? Trying to have a parameter drop down list where a user can select one or more of the available values contained in the table to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.