?
Solved

Syntax error in VBA SQL. I can't see the problem.

Posted on 2014-09-22
3
Medium Priority
?
200 Views
Last Modified: 2014-09-22
Can you see a syntax error here please. I get message below.

Dim rstIncomesSQL As String
Dim rstIncomes As DAO.Recordset

Dim strClientId As String

strClientId = "4105095040088"

rstIncomesSQL = "SELECT tblIncomeAndInvestments.* FROM tblIncomeAndInvestments WHERE (tblIncomeAndInvestments.[IncGrowProp])='Income' AND (tblIncomeAndInvestments.[CLIENTID)]= '" & strClientId & "';"

Set rstIncomes = db.OpenRecordset(rstIncomesSQL, dbOpenSnapshot)

Open in new window


Syntax error message
This however works fine:

rstIncomesSQL = "SELECT tblIncomeAndInvestments.* FROM tblIncomeAndInvestments WHERE (tblIncomeAndInvestments.CLIENTID)= '" & strClientId & "';"

Open in new window


The problem comes when I add the

(tblIncomeAndInvestments.[IncGrowProp])='Income' AND   section. "Income" is a value in IncGrowProp field.

Here is a snap of the table
tblIncomeAndInvestments.JPG
0
Comment
Question by:Fritz Paul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 2000 total points
ID: 40336296
You've got [CLIENTID)] - open hard bracket - CLIENTID - close soft bracket - close hard bracket.

You need [CLIENTID]) - open hard bracket - CLIENTID - close hard bracket - close soft bracket
0
 
LVL 27

Expert Comment

by:MacroShadow
ID: 40336301
You've got a typo:
tblIncomeAndInvestments.[CLIENTID)]
should be:
tblIncomeAndInvestments.[CLIENTID])
0
 

Author Closing Comment

by:Fritz Paul
ID: 40336354
Thanks. I was so stupid.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question