Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > MS Access VBA/SQL - Incomplete Query Clause


Reply
 
Thread Tools Display Modes
  #1  
Old 10-19-2010, 09:01 AM
panyd panyd is offline
Newcomer
 
Join Date: Oct 2010
Posts: 1
Question MS Access VBA/SQL - Incomplete Query Clause


Hi there,

I've been working on some code and I've had a few issues with it. It's now got to the point where it appears to be very close to working, but I keep getting the Incomplete Query Clause error message. Can anybody help?

Code below:

Private Sub Command83_Click()

Dim strSQL As String
Dim strCriteria As String

strSQL = ""
strSQL = strSQL & " INSERT INTO '[Merchant CCF]([Merchant Name][Merchant Type][Partner][Merchant Sector]')"
strSQL = strSQL & " SELECT ([Merchant Name][Merchant Type][Partner][Merchant Sector])"
strSQL = strSQL & " FROM [Main table]"
strSQL = strSQL & " WHERE ((([Main table](ID)) BETWEEN 1 AND 5000 AND (([Merchant CCF](Test_ID)) BETWEEN 1 AND 5000)));"
DoCmd.RunSQL strSQL, False

End Sub
Reply With Quote
  #2  
Old 10-19-2010, 10:33 AM
Mkjo99 Mkjo99 is offline
Regular
 
Join Date: May 2009
Posts: 53
Default

Did you try to look at the value of strSQL?
If you are dynamically buiding a query and it fails that should be the first thing you do. Here is what your query looks like:
Code:
INSERT INTO '[Merchant CCF]([Merchant Name][Merchant Type][Partner][Merchant Sector]') 
SELECT ([Merchant Name][Merchant Type][Partner][Merchant Sector]) 
FROM [Main table] 
WHERE ((([Main table](ID)) BETWEEN 1 AND 5000 AND (([Merchant CCF](Test_ID)) BETWEEN 1 AND 5000)));
See anything wrong with it? This is what it should look like:
Code:
INSERT INTO [Merchant CCF] ([Merchant Name],[Merchant Type],[Partner],[Merchant Sector]) 
SELECT [Merchant Name],[Merchant Type],[Partner],[Merchant Sector]
FROM [Main table] 
WHERE [Main table].ID BETWEEN 1 AND 5000 AND [Merchant CCF].Test_ID BETWEEN 1 AND 5000;
.
Another problem you have is you do not reference the table [Merchant CCF] in the FROM part of your select statement. You need to create a join between [Main table] and [Merchant CCF]. Finally, you shouldn't put all of those parenthesis in your where clause unless you actually need them. They just make it messier to read.
Reply With Quote
Reply

Tags
access, sql, vba


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->