[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

VBA issues with Excel 2007 talking to Access 2007 DB

Posted on 2009-06-29
8
Medium Priority
?
632 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 2000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

656 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