Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2015, 05:47 AM
Registered User
 
Join Date: Sep 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Query does not run usingDoCmd.RunSQL

Hi,

I have below SQL query which executes when run as a query; but when same is run using DoCmd.RunSQl it gives error.

DoCmd.RunSQL "INSERT INTO Test" & _
"SELECT ClashReport250815.[#ITEM_HIERARCHY_A#] AS [#ITEM_HIERARCHY_A#], ClashReport250815.[#CLASH_ID#] AS [#CLASH_ID#]" & _
"FROM LINE_ID, ClashReport250815" & _
"WHERE ((("" & ClashReport250815.[#ITEM_HIERARCHY_A#] & "") Like " * " & LINE_ID.Field1 & " * "))"


Please suggest the correct syntax.
 
Old September 2nd, 2015, 04:46 PM
Friend of Wrox
 
Join Date: Sep 2010
Posts: 245
Thanks: 5
Thanked 24 Times in 23 Posts
Default

What is the erro mesage?


Quote:
Originally Posted by rai.unmesh View Post
Hi,

I have below SQL query which executes when run as a query; but when same is run using DoCmd.RunSQl it gives error.

DoCmd.RunSQL "INSERT INTO Test" & _
"SELECT ClashReport250815.[#ITEM_HIERARCHY_A#] AS [#ITEM_HIERARCHY_A#], ClashReport250815.[#CLASH_ID#] AS [#CLASH_ID#]" & _
"FROM LINE_ID, ClashReport250815" & _
"WHERE ((("" & ClashReport250815.[#ITEM_HIERARCHY_A#] & "") Like " * " & LINE_ID.Field1 & " * "))"


Please suggest the correct syntax.


The first issue that I spotted was that you need an extra space at the beginning the continuation lines after the quotes.

Code:
               "FROM LINE_ID, ClashReport250815" & _
to

Code:
               " FROM LINE_ID, ClashReport250815" & _

Code:
                "WHERE ((("" & ClashReport250815.[#ITEM_HIERARCHY_A#] & "") Like " * " & LINE_ID.Field1 & " * "))"
to

Code:
                " WHERE ((("" & ClashReport250815.[#ITEM_HIERARCHY_A#] & "") Like " * " & LINE_ID.Field1 & " * "))"
__________________
Boyd Trimmell aka HiTechCoach (.com)
Microsoft Access MVP Alumni 2010-2015





Similar Threads
Thread Thread Starter Forum Replies Last Post
Coverting SQL to DoCmd.RunSQL dem1an Access VBA 2 June 26th, 2013 10:30 AM
Update query doesnt run when Select query does (In MS Access) rmccafferty SQL Language 3 February 11th, 2010 04:54 AM
How Run .sql Script file in MS SQL Server 2000? aarkaycee SQL Server 2000 5 October 12th, 2009 05:43 AM
Set query up to automatically run in SQL server ALLA SQL Server 2000 3 October 21st, 2004 04:24 PM
Query to be run against both SQL and Oracle NK Oracle 2 April 26th, 2004 05:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.