Solved

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

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
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 …

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now