Solved

VBA issues with Excel 2007 talking to Access 2007 DB

Posted on 2009-06-29
8
606 Views
Last Modified: 2012-05-07
1) I have an Excel 2007 App that interfaces with an Access 2007 db using VBA code. I have a simple data import statement (using TransferText) that imports raw text data into a staging table in Access. This works fine.
2) After this, I construct a simple "INSERT INTO prodtable SELECT * FROM stagingtable " query,
and try to submit it for execution via VBA.
3) The above query works only if I have the VBA code window open and I step through the code.
3) the above query fails if I have the VBA code window closed.Might strange eh?
4) Can someone educate me as to what is going on with Excel 2007 vba and Access db? More importantly, how do I ensure that this query works consistently all the time?

Any and all help seriously appreciated.
0
Comment
Question by:choochim
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 39

Accepted Solution

by:
thenelson earned 500 total points
ID: 24736502
Is the query in step 2 acting on the data transpired in step 1?  If so, then the query in probably running before the transfer completes.  (TransferText is asynchronous meaning the code continue while TransferText processes).  You can put a bunch of DoCmd command after the TransferText to stall or better, you can install a do loop after the TransferText to look for the last data transfered.
0
 

Author Closing Comment

by:choochim
ID: 31597931
thenelson:
Your expert advice is right on the money.  The app works as designed now with queries firing all be it a few seconds delayed to counteract the async data transfer. Thanks for the timely help.
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24737231
Did you use DoCmd or the do loop?

You're welcome.  Glad to help and thank you very much for the points with "A" grade!

Happy Computing!

Nelson
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:choochim
ID: 24737360
thenelson:

I ended up using a Do While Loop with a windows Timer to pause for 5 seconds.

Unfortunately, no sooner I finished submitting my response - the VBA code once again started 'misbehaving' on an "UPDATE" query fired from within VBA. This time - the query runs perfectly fine when executed inside Access query designer, while the same query does not work from within VBA. No errors reported, but data does not get updated. Any clues?
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24737700
Might still be timing. If you wait a specific amount of time, the TransferText may take longer some times.  In the do loop, do a record count of the staging table.  When it stops growing, leave the loop.
0
 

Author Comment

by:choochim
ID: 24738295
actually the "UPDATE prodtable" query fires in the third step after the "INSERT INTO prodtable" query. So it cannot be the Transfertext since this is the first step in getting the raw text file into the access staging table. Then comes the "INSERT INTO prodtable SELECT * FROM stagetable" statement. Then comes the "UPDATE" step. Step 1 and 2 work correctly. It failes always with Step 3.
0
 
LVL 39

Expert Comment

by:thenelson
ID: 24741060
Could be timing again with the update query running before the Insert query finishes. Queries are also asynchronous.  Try adding another delay loop after the insert query.
0
 

Author Comment

by:choochim
ID: 24744536
will try that. I did not know that pass through queries are also fired async from VBA to access. I learning something today. Thanks
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

733 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