473,396 Members | 1,963 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,396 software developers and data experts.

Queries with field names defined by a control in a form

I want to create a select query where I can define which field is used
by a control in a form.

For instance if I have a table tServices, in which there are fields
ServiceDate, ServiceType, ServiceCategory, ServiceName

Rather than creating three separate queries to view ServiceDate
combined with one of the other fields, I would like to define the
field by selecting it from a form, for instance:

Select ServiceDate, [Forms]![Form1]![txtFieldName] as
SelectedFieldName
FROM tServices

The above query doesn't do what I want, it just creates a field where
every record has the selected field name, rather than the data stored
in that field. How do I write the expression properly?

I have created ways to work around this, using modules with
docmd.runsql method, because then I can define the sql as a text
string and insert variables into it as certain points. However, this
isn't really what I want to do.... I just want a select query, not an
action query.

Thanks to all who have given advice in previous queries!

gwin
Nov 13 '05 #1
3 1093
Gwin <do*********@verizon.net> wrote in
news:s8********************************@4ax.com:
I want to create a select query where I can define which field
is used by a control in a form.

For instance if I have a table tServices, in which there are
fields ServiceDate, ServiceType, ServiceCategory, ServiceName

Rather than creating three separate queries to view
ServiceDate combined with one of the other fields, I would
like to define the field by selecting it from a form, for
instance:

Select ServiceDate, [Forms]![Form1]![txtFieldName] as
SelectedFieldName
FROM tServices

The above query doesn't do what I want, it just creates a
field where every record has the selected field name, rather
than the data stored in that field. How do I write the
expression properly?

I have created ways to work around this, using modules with
docmd.runsql method, because then I can define the sql as a
text string and insert variables into it as certain points.
However, this isn't really what I want to do.... I just want
a select query, not an action query.

Thanks to all who have given advice in previous queries!

gwin

Instead of using the runsql method, change the code to
createquerydef, openquery and then delete the querydef
--
Bob Quintal

PA is y I've altered my email address.
Nov 13 '05 #2
You'll have to build the SQL statement yourself in a string variable
and then assign it to a query's SQL property and save the query.
Nov 13 '05 #3
Where is this headed? Can you assign the string to the RecordSource of the
form or report? Or even to the SQL property of the QueryDef?

strSql = "SELECT ServiceDate, " & Forms!Forms1!txtFieldName & " AS
dbEngine(0)(0).QueryDefs("Query1").SQL = strSql

--
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.

"Gwin" <do*********@verizon.net> wrote in message
news:s8********************************@4ax.com...
I want to create a select query where I can define which field is used
by a control in a form.

For instance if I have a table tServices, in which there are fields
ServiceDate, ServiceType, ServiceCategory, ServiceName

Rather than creating three separate queries to view ServiceDate
combined with one of the other fields, I would like to define the
field by selecting it from a form, for instance:

Select ServiceDate, [Forms]![Form1]![txtFieldName] as
SelectedFieldName
FROM tServices

The above query doesn't do what I want, it just creates a field where
every record has the selected field name, rather than the data stored
in that field. How do I write the expression properly?

I have created ways to work around this, using modules with
docmd.runsql method, because then I can define the sql as a text
string and insert variables into it as certain points. However, this
isn't really what I want to do.... I just want a select query, not an
action query.

Thanks to all who have given advice in previous queries!

gwin

Nov 13 '05 #4

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

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
2
by: Tom Cusick | last post by:
MS Access Version 2002 (10.4302.4291) SP-2 Windows XP Pro 2002 SP-1 ----------------------------------------------------------------- Ok my question is this. I have one form laid out the way I...
3
by: Keith Wilby | last post by:
I have a form which allows both form and datasheet views. My question is, is it possible to control the field (column) names in datasheet view? What happens at the moment is that the name is...
2
by: Tim Pollard | last post by:
Hi I'm hoping someone can help me with an access problem I just can't get my head around. I normally use access as a back end for asp pages, just to hold data in tables, so queries within access...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
3
by: mikes | last post by:
I have 2 separate queries, which effectively are the same except they draw data from separate tables. Both tables are (design-wise) identical, only the data is different. for each query, there are...
43
by: Woodies_46 | last post by:
Hi all, I'm just a little bit stuck... what i have is a form with tick boxs and text boxs and stuff like that on it and a search button. What I would like to be able to do is for the user to...
14
by: mchlle | last post by:
How can I filter records of a subform that is part of a tab control? The filter works fine on the form when it is not part of the tab using this in the macro condition: !!="Today" I have a main...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.