?
Solved

VBA issues with Excel 2007 talking to Access 2007 DB

Posted on 2009-06-29
8
Medium Priority
?
621 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
Technology Partners: 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!

 

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

Industry Leaders: 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

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 article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

770 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