Solved

Query string concatenation in Access SQL

Posted on 2009-04-06
2
1,198 Views
Last Modified: 2013-11-27
I wish to concatenate two or more SQL queries on an Access database, eg in the Code snippet

I can do this on a SQL Server database but Access does not like it.  It doesnt like me using semi-colon separators either.

 How can I make it work in Access?

sSQL = " DECLARE @oldMaxItemID int " _
 

                & " SET @oldMaxItemID = ( SELECT MAX(ItemID) " _
 

                & " FROM Controls ) " _
 

                & " " _
 

                & " INSERT INTO Controls " _
 

                & " SELECT ApplicationName, FormName, ParentName, " _
 

                & " ControlName, ControlType, ControlText, ControlBackColour, ControlForeColour, " _
 

                & " LanguageCode, TranslatedControlText " _
 

                & " FROM Controls " _
 

                & " WHERE LanguageCode = '" & AUST_ENGLISH_LANGUAGE_CODE & "' " _
 

                & " AND ApplicationName = '" & anApplicationName & "'  "
 

 
 

            sSQL = sSQL & " UPDATE Controls " _
 

                & " SET LanguageCode = '" & aLanguageCode & "' " _
 

                & " WHERE ItemID > @oldMaxItemID "
 

 
 

            sSQL = sSQL & " DECLARE @oldMaxMessageID int " _
 

                & " SET @oldMaxMessageID = ( SELECT MAX(MessageID) " _
 

                & " FROM Message ) " _
 

                & " " _
 

                & " INSERT INTO Message " _
 

                & " SELECT ApplicationName, Message, " _
 

                & " LanguageCode, [Translation] " _
 

                & " FROM Message " _
 

                & " WHERE LanguageCode = '" & AUST_ENGLISH_LANGUAGE_CODE & "' " _
 

                & " AND ApplicationName = '" & anApplicationName & "'  "
 

 
 

            sSQL = sSQL & " UPDATE Message " _
 

                & " SET LanguageCode = '" & aLanguageCode & "' " _
 

                & " WHERE MessageID > @oldMaxMessageID "

Open in new window

0
Comment
Question by:edwardr
2 Comments
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
Comment Utility
You cannot concatenate SQL queries in Access.

You must run them one at a time indivudually:

Something like this:

CurrentDB.Execute "Select...", dbFailonError
CurrentDB.Execute "Delete...", dbFailonError
CurrentDB.Execute "Insert...", dbFailonError

JeffCoachman

0
 

Author Closing Comment

by:edwardr
Comment Utility
That works.
Thanks.
EdwardR
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

744 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

15 Experts available now in Live!

Get 1:1 Help Now