Solved

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

Posted on 2014-09-22
3
199 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 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

705 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