473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Getting Different Results: Query in VBA VS same in Query Wizard

1
Hi there!

I am trying to run the following simple query from within VBA:

"
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO tempTable SELECT * FROM Deletions"
"


When I run this from the Access 2003 query wizard in SQL view, it executes just fine. When I move to my form code and try running it with:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO tempTable SELECT * FROM Deletions"
or
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.execute "INSERT INTO tempTable SELECT * FROM Deletions"

It does not work. I've also tried this by assigning the queries to string variables and using DoCmd.RunSql and CurrentDb.execute on the string varaibles, but that makes no difference. The DoCmd will give me the notice it is going to append 0 (zero) rows - while running the same query in the SQL view of the wizard gives me notice it is going to append the correct number of rows. I am trying to automate this as part of a process, so I really want to do this from VBA and not have to go through the Access queries / wizard each time. Is there any reason why a query would act differently between the SQL view of the wizard and the VBA methods here?

Thanks!
Dec 21 '07 #1
1 2424
puppydogbuddy
1,923 Expert 1GB
Hi there!

I am trying to run the following simple query from within VBA:

"
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO tempTable SELECT * FROM Deletions"
"


When I run this from the Access 2003 query wizard in SQL view, it executes just fine. When I move to my form code and try running it with:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL "INSERT INTO tempTable SELECT * FROM Deletions"
or
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.execute "INSERT INTO tempTable SELECT * FROM Deletions"

It does not work. I've also tried this by assigning the queries to string variables and using DoCmd.RunSql and CurrentDb.execute on the string varaibles, but that makes no difference. The DoCmd will give me the notice it is going to append 0 (zero) rows - while running the same query in the SQL view of the wizard gives me notice it is going to append the correct number of rows. I am trying to automate this as part of a process, so I really want to do this from VBA and not have to go through the Access queries / wizard each time. Is there any reason why a query would act differently between the SQL view of the wizard and the VBA methods here?

Thanks!
An SQL statement must finish with a semicolon (;). If you omit the semicolon when writing an SQL statement in the SQL view of the Access query design window your query will still work because Access corrects the error for you! You must remember to include it when writing SQL in VBA and elsewhere.


Change this:
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.execute "INSERT INTO tempTable SELECT * FROM Deletions"

To (note the semi-colon at the end)
Expand|Select|Wrap|Line Numbers
  1. CurrentDb.execute "INSERT INTO tempTable SELECT * FROM Deletions;"
Dec 22 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
8
by: Bruce Dodds | last post by:
When run manually, my query appends 14 records. When run from code using CurrentProject.Connection.Execute, the same query appends 11 records. Does anyone have an explanation of why this could be...
4
by: Martin Lacoste | last post by:
Can I get field names to be returned as data in a query's results? E.g. I have 3 fields (City, Town, Village), and want the results to incorporate these as data, e.g.: City 2 Town 4...
1
by: Megan | last post by:
Hi everybody- For some reason, I cannot get this query to work. I have 2 identical tables. One table is new, the other is old. I want to be able to tell which records in the newer table are...
7
by: Alex L Pavluck | last post by:
Hello. I have my data setup as follows: Main MEMNAME NAME TYPE LABEL Variable MEMNAME VARNAME NUMBER Format MEMNAME FMTVALUE NUMBER
7
by: fcolon75 | last post by:
I'm an experienced Access user, but very new to coding VBA in Access. I'd like to do the following: 1) Develop a basic query in the query designer. 2) Call that query from a VBA script 3)...
3
by: Bill Hutchison | last post by:
I have a query that returns different results (3508 rows for snapshot, 6288 for dynaset) and that is the only thing I change to get the different results. When I try to make a table from the...
4
by: Belgarath | last post by:
Hello all, I'm a newbie in Access... And before starting to explore this software, I would like to know if it's possible to automate everyday queries result in Excel . If it's possible can...
1
by: lawton | last post by:
Source: this is an access 2003 question My knowledge level: reading books, internet, and trial & error; no formal training I'm trying to get a running sum of what's filtered in a subform which is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.