Solved

VBA issues with Excel 2007 talking to Access 2007 DB

Posted on 2009-06-29
8
572 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
  • 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

760 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

16 Experts available now in Live!

Get 1:1 Help Now