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

Parameter syntax error

39
Hello all,

I am at a lost with troubleshooting my SQL string. I am receiving a “Syntax error in parameter clause”.

I do not think I have exceeded the number of characters for a SQL string.

Also ensured the semicolon after the Parameters line and inserted with “& _” on each end within my VBA code.

All parameters are text. When I tried in Access' Query tool without parameters, the query runs.

Do you see where I went wrong?

Thanks.

Expand|Select|Wrap|Line Numbers
  1.  
  2. strSQL = "PARAMETERS [Forms]![frmB]![cboB] Text ( 255 ), [Forms]![frmB]![lstT] Text ( 255 ), [Forms]![frmB]![lstSolution] Text ( 255 ), [Forms]![frmB]![lstReporting] Text ( 255 ), [Forms]![frmB]![lstReporting] Text ( 255 ), [Forms]![frmB]![lstProjType] Text ( 255 ), [Forms]![frmB]![lstS] Text ( 255 ), [Forms]![frmB]![lstArea] Text ( 255 ); " & _
  3.         "SELECT tbMastfinal.Funding, tbGP.GrProgram, tbT.TCLIDname, tbSA.SAName, tbStates.StateName, tbRP.RPname, tbProjectTypes.ProjectTypeName, tbRegions.RegionName, tbArea.AName  " & _
  4.         "FROM tbT INNER JOIN (tbProjectTypes INNER JOIN (tbGP INNER JOIN (tbRegions INNER JOIN (tbArea INNER JOIN (tbSA INNER JOIN (tbRP INNER JOIN (tbStates INNER JOIN tbMastfinal ON tbStates.StateID = tbMastfinal.StateID) ON tbRP.RP_ID = tbMastfinal.RP_ID) ON tbSA.SA_ID = tbMastfinal.SA_ID) ON tbArea.AreaID = tbMastfinal.AreaID) ON tbRegions.RegionID = tbMastfinal.RegionID) ON tbGP.GrPrgID = tbMastfinal.GrPrgID) ON tbProjectTypes.ProjectTypeID = tbMastfinal.ProjectTypeID) ON tbT.TCLID = tbMastfinal.TCLID  " & _
  5.         "WHERE (((tbGP.GrProgram)=[Forms]![frmB]![cboB]) AND ((tbT.TCLIDname)=[Forms]![frmB]![lstT]) AND ((tbSA.SAName)=[Forms]![frmB]![lstSolution]) AND ((tbStates.StateName)=[Forms]![frmB]![lstReporting]) AND ((tbRP.RPname)=[Forms]![frmB]![lstReporting]) AND ((tbProjectTypes.ProjectTypeName)=[Forms]![frmB]![lstProjType]) AND ((tbRegions.RegionName)=[Forms]![frmB]![lstS]) AND ((tbArea.AName)=[Forms]![frmB]![lstArea]));"
  6.  
Sep 21 '11 #1
16 3815
Rabbit
12,516 Expert Mod 8TB
Take out the parameter stuff at the beginning. If you're trying to reference a control on a form, you don't need it.
Sep 21 '11 #2
patjones
931 Expert 512MB
Hi Qtip,

The concern I have has to do with the parameters themselves. What you're trying to do is pass text box values from your form directly into the query using the PARAMETERS clause, and I don't think that can work. You would need to call the parameters something else and then do an explicit assignment for each one using the Parameters collection of your QueryDef object:

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2. Dim qdf As DAO.QueryDef
  3.  
  4. strSQL = "PARAMETERS [CriteriaValue] TEXT; " & _
  5.          "SELECT * FROM SomeTable WHERE SomeColumn = [CriteriaValue];"
  6.  
  7. Set qdf = CurrentDb.CreateQueryDef("QueryName", strSQL)
  8. qdf.Parameters("CriteriaValue") = Me.txtBoxValue

What we're doing here is defining the parameter name and type within the SQL string...but it's completely arbitrary at this point. The parameter does not take on the value from the text box on the form until the qdf.Parameters assignment.

Pat
Sep 21 '11 #3
patjones
931 Expert 512MB
Per Rabbit's suggestion, if you remove the PARAMETERS clause you can use the control values in the WHERE clause as you are trying to do, but you cannot include them inside the SQL string; they must be concatenated with the string. For example:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT ...
  2.           FROM ...
  3.           WHERE (((tbGP.GrProgram)= " & [Forms]![frmB]![cboB] & ")  AND ((tbT.TCLIDname)= " & [Forms]![frmB]![lstT] & ")"
Sep 21 '11 #4
patjones
931 Expert 512MB
If you stick with the parameters, I just made a couple of small corrections to my syntax and added in how you would connect the query results to a recordset and string variable. This query pulls an employee's name based on an employee ID search from text box 'txtEmplID'.

Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String, strResult As String
  2. Dim rst As DAO.Recordset
  3. Dim qry As DAO.QueryDef
  4.  
  5. strSQL ="PARAMETERS EmplID CHAR; SELECT fldNameLast, fldNameFirst FROM tblEmployees WHERE fldID = EmplID;")
  6.  
  7. Set qry = CurrentDb.CreateQueryDef("getEmplName", strSQL)
  8. qry!EmplID = Me.txtEmplID
  9.  
  10. Set rst = qry.OpenRecordset(dbOpenSnapshot)
  11. str = rst("fldNameLast") & ", " & rst("fldNameFirst"
  12.  
  13. Set rst = Nothing
  14. Set qry = Nothing
Sep 21 '11 #5
Qtip23
39
@Rabbit

Thanks for the response. I tried removing just the Parameter statement first. Initially, I received a parameter pop up box when I opened the form. So I continued troubleshooting and tried the other recommendations. This proved to be a good first step.

@Zepphead80

Thanks for your response too. I am using ADO to connect my query results (should not matter though). I noticed that by not using any parameters in my WHERE clause, I was able to run a master query with no issue.

However, this is really not what I want. I would like to limit the query to the filter selection. So I started small and reduced to just one field to see what was happening.

I have tried various options on my form control which I did not mention are seven list boxes.
Instead of "WHERE (((tbGP.GrProgram)=[Forms]![frmB]![lstB]) " , I tried:
Expand|Select|Wrap|Line Numbers
  1. '""Me.lstB.ItemData(varItem)""'
  2. '"" & Me.lstB.ItemData(varItem) & ""'
  3. '"" & Me.lstB.Value & ""'
  4.  
  5.  
Do you think I have too many parentheses?
Sep 22 '11 #6
patjones
931 Expert 512MB
I'm not entirely sure what you wrote. You want the SQL to look something like this:

Expand|Select|Wrap|Line Numbers
  1. "SELECT ...
  2.  FROM ...
  3.  WHERE tbGP.GrProgram = " & [Forms]![frmB]![lstB] & " AND  
  4.        ..."

Notice that the reference to the list box resides outside the SQL string. I'm assuming here that lstB contains a number. If it's a text value or date, the value needs to be encapsulated in ' ' or # # respectively.

Pat
Sep 22 '11 #7
Qtip23
39
Not having much luck with the parameters. So I am using a variable to store the value of the control.

I have my Immediate Window open and in debug mode on the string. I see the values that I select. However, the SQL string does not run. I am receive a weird error message -- Method "Command" of object 'View" failed. What could be causing this?

Here is the code I use to apply the SQL statement to the stored query

Expand|Select|Wrap|Line Numbers
  1.     cat.ActiveConnection = CurrentProject.Connection
  2.     Set cmd = cat.Views("qryALL_B").Command
  3.     cmd.CommandText = strSQL
  4.     Set cat.Views("qryALL_B").Command = cmd
  5.     Set cat = Nothing
  6.  
Sep 23 '11 #8
Qtip23
39
After further research on Bytes and other sources, looks like there maybe an issue with the DLL's and Access 2007 when using ADO. So I am going to try DAO.

Let me see what happens.

Qtip23
Sep 23 '11 #9
patjones
931 Expert 512MB
You don't need to assign variables and you don't need parameters. You can embed the controls in the SQL just as I'm saying in post #7.
Sep 26 '11 #10
NeoPa
32,556 Expert Mod 16PB
There are two main ways to reference such values using SQL :
  1. A direct reference to the controls themselves within your SQL :
    Expand|Select|Wrap|Line Numbers
    1. SELECT [Forms]![frmB].[lstB]
  2. Using VBA to insert the actual value of the control into the string :
    Expand|Select|Wrap|Line Numbers
    1. strSQL = "SELECT '" & [Forms]![frmB].[lstB] & "'"

I have very little experience of using the PARAMETERS clause in SQL, but I understand there are situations where it may be appropriate to use it (for option #1) because it is otherwise ambiguous as to how to treat the data referenced.

@Pat The SQL in post #7 seems to treat the item as numeric, but all the items in the original PARAMETERS clause were text. I would guess quotes are required.

@Qtip I would suggest, if you are still struggling with this, that you throw away most of the unrequired contents of your SQL and break it down into something much smaller with which to test out the concepts. When you have these sorted out would be a good time to build up your SQL based on your new, and thorough, understanding of the concepts required.
Sep 26 '11 #11
Qtip23
39
@NeoPa I did exactly as you suggested -- breakdown my SQL into smaller parts. What I am learning is the power of action queries.

Instead of focusing on the parameters in SQL string, I have taken them out completely. I have taken another completely different approach.

Having more success by using a combination of the control values and action queries (i.e. insert, append and delete queries) throughout my development.

Thanks for the feedback.
Sep 28 '11 #12
patjones
931 Expert 512MB
Your query is not an action query though. It's a SELECT query which simply pulls data from the tables rather than adding, deleting or modifying anything. So how is it that you're accomplishing your goal?
Sep 28 '11 #13
Qtip23
39
@zepphead80 you are right. what I meant was that I took a step back and re-evaluated my whole approach to building this particular Access application.

I used the SQL string as suggested above (without the parameters). Yet incorporated other action queries to manipulate data selected by the user, etc. Still working on this effort as we speak.
Sep 28 '11 #14
patjones
931 Expert 512MB
OK, well if you run into any other issues then let us know!
Sep 28 '11 #15
NeoPa
32,556 Expert Mod 16PB
In view of what sounds like an eminently sensible approach to progress, I suggest we consider this done. We don't know precisely what changes you've made, but it sounds like they are fundamental enough to render this question, with the related information, obsolete.
Sep 28 '11 #16
Qtip23
39
@NeoPa your assessment is correct. case closed.
Sep 28 '11 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Andreas Neudecker | last post by:
Hello. I am relatively new to Python and I have a strange problem with some code. In a class the __call__ method gets parameters like this: class WhatsUp: __call__ ( self, var1,
2
by: kalpana.sinduria | last post by:
Hi all, how to remove the following complle error. When I compiling the code I get the following errors: Compiling... CDrtEachDefFeat.cpp d:\ include\common\cdrtintegfeat.h(39) : error...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
4
by: Peter | last post by:
Hello, Thanks for reviewing my question. I am just starting out create a custom control following the KB example "Create a Data Bound ListView Control". I am receiving a syntax error on the...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
3
by: Jerry | last post by:
Well, here is some weirdness. First, I noticed that I have 2 Set keywords (silly me). so I removed the 2nd "Set" but still got a syntax error. Then I removed the Where clause, and now it works...
3
by: nvr | last post by:
Hi all I am doing the socket programming for the client side. but the code is not compiling and i am getting the below error ./Clientsend.c: line 11: syntax error near unexpected token `('...
6
by: Pixel.to.life | last post by:
So I have this perfectly fine and running app, that uses managed C++ forms. Problem#1: I pass a Bitmap reference to a class, hoping to modify it in one of the class's methods, so it...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
3
by: lingjun | last post by:
Hi, I am taking my first programing course in college... and I am completely lost on this assignment. I am not sure what is wrong with my current code. Any help will be appreciate it... thanks! ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.