473,486 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Change SQL with code

I'm need to change my SQL based upon the field that the user selects on
a form. To follow is the beginning of my code. The selected field is
represented by fName. When I run it I get syntax error 3075 and I think
the problem is that fName returns the field name with quotation marks
around it. Any suggestions as to how I can make this work?

Dim Db As Database, qdf As QueryDef, strSQL As String

fName = DLookup("QuestionName", "tblQuestionNames", "QuestionIDNumber =
[Forms]![frmSampleSize]![QNumber]")

strSQL = "SELECT Questionnaire.[Fiscal Year], Questionnaire.[Quarter],
Questionnaire. & fName & FROM Questionnaire "
strSQL = strSQL & "WHERE Questionnaire.[Fiscal Year] = '2006' & '/' &
'07'; "

Sep 20 '06 #1
2 1314
I inserted quotes and square brackets for you:

strSQL = "SELECT Questionnaire.[Fiscal Year], Questionnaire.[Quarter],
Questionnaire.[" & fName & "] FROM Questionnaire "
Delores schreef:
I'm need to change my SQL based upon the field that the user selects on
a form. To follow is the beginning of my code. The selected field is
represented by fName. When I run it I get syntax error 3075 and I think
the problem is that fName returns the field name with quotation marks
around it. Any suggestions as to how I can make this work?

Dim Db As Database, qdf As QueryDef, strSQL As String

fName = DLookup("QuestionName", "tblQuestionNames", "QuestionIDNumber =
[Forms]![frmSampleSize]![QNumber]")

strSQL = "SELECT Questionnaire.[Fiscal Year], Questionnaire.[Quarter],
Questionnaire. & fName & FROM Questionnaire "
strSQL = strSQL & "WHERE Questionnaire.[Fiscal Year] = '2006' & '/' &
'07'; "
--
Bas Cost Budde
Holland
Sep 20 '06 #2
That did the trick - thank you!

Sep 20 '06 #3

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

Similar topics

8
9157
by: Patrick Kowalzick | last post by:
Dear NG, I would like to change the allocator of e.g. all std::strings, without changing my code. Is there a portable solution to achieve this? The only nice solution I can think of, would be...
12
3033
by: Arno R | last post by:
Hi there, I just distributed an application in which I (try to) change db.properties depending on CurrentUser() For instance I set the property's AllowBypassKey and AllowBuiltinToolbars to False...
3
4977
by: Tom | last post by:
I am writing a Visual basic .Net database application. There are many forms that first let you select and look at a DB record and then when you click a "modify" button you are allowed to change...
5
7858
by: Elena | last post by:
I need the VB.NET code to change the header/footer of an Excel spread sheet, ASAP. I am doing it through a VB application. I can change the ranges/cell values using code, but I do not know how to...
11
7431
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RowSource of a Master Report is: Me.RowSource = "TableOrQueryName"
3
9364
by: Simon | last post by:
Dear reader, The syntax for the VBA code to change the RecordSource of a Master Report is: Me.RecordSource = "TableOrQueryName"
25
30762
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
4
2206
by: Heikki Toivonen | last post by:
I was debugging M2Crypto function written in C which changed behavior between Python 2.6 and earlier Python versions. In an error condition the function was supposed to raise exception type A, but...
15
3692
by: Sunny | last post by:
Hi, I can change the lement opacity in IE using. abc.style.filter = 'alpha(opacity=' + 10 + ')'; But this dont work in firefox, In firefox it throws error. How I can change the opacity of an...
2
5066
by: bemytthm | last post by:
I just want to ask abt communicate with AD using ASP.net. I would want to ask you all to help me correct a problem like this: This is a code i use to change password on AD public bool...
0
7099
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
6964
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
7175
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...
1
6842
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
7319
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5430
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
3069
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.