Solved

VBA issues with Excel 2007 talking to Access 2007 DB

Posted on 2009-06-29
8
591 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select Next Route by Time 4 19
Merging spreadsheets 8 41
If help 9 48
Advice on Listbox or Listview usage 3 13
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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.

773 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