Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default Error Handling

I'm running this code from Excel to import a file into Access.

Dim QueryName, Location As String
Set AccApp = GetObject(, "Access.Application")

QueryName = "Clear Table"
AccApp.DoCmd.OpenQuery QueryName

Location = "C:\North America\Offices.csv"
AccApp.DoCmd.TransferText acImportDelim, "Dept Specification", "Dept",
Location, False

The problem is when someone already has the Offices.csv file already open.
If no one has the file opened, this works just fine. Otherwise, there is an
Access error message that the file is already opened. The issue is you have
to click on Access to see the message. To the user, it appears that the
Excel macro is still running.

If the macro encounters this situation, I would prefer a message be
displayed by Excel and leave Access out of it. Ultimately, I would like for
the macro to (1) click "OK" for the Access message, (2) display a msg in
Excel, and (3) end the macro. This will allow the user to try again in a few
minutes.

I'm using Access to import recrods because there are more than 65,000
records. Otherwise I would just do the whole thing in Excel.

**** code continues*****

QueryName = "Create Reference"
AccApp.DoCmd.OpenQuery QueryName

etc.

Any help on solving this problem, would be greatly appreciated. Thanks for
the help.
--
JT
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Error Handling

Check if you can get exclusive access before you try to use it in Access:


http://support.microsoft.com?kbid=138621
XL: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=291295
XL2002: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=213383
XL2000: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=184982
WD97: VBA Function to Check If File or Document Is Open

--
Regards,
Tom Ogilvy


"JT" wrote:

I'm running this code from Excel to import a file into Access.

Dim QueryName, Location As String
Set AccApp = GetObject(, "Access.Application")

QueryName = "Clear Table"
AccApp.DoCmd.OpenQuery QueryName

Location = "C:\North America\Offices.csv"
AccApp.DoCmd.TransferText acImportDelim, "Dept Specification", "Dept",
Location, False

The problem is when someone already has the Offices.csv file already open.
If no one has the file opened, this works just fine. Otherwise, there is an
Access error message that the file is already opened. The issue is you have
to click on Access to see the message. To the user, it appears that the
Excel macro is still running.

If the macro encounters this situation, I would prefer a message be
displayed by Excel and leave Access out of it. Ultimately, I would like for
the macro to (1) click "OK" for the Access message, (2) display a msg in
Excel, and (3) end the macro. This will allow the user to try again in a few
minutes.

I'm using Access to import recrods because there are more than 65,000
records. Otherwise I would just do the whole thing in Excel.

**** code continues*****

QueryName = "Create Reference"
AccApp.DoCmd.OpenQuery QueryName

etc.

Any help on solving this problem, would be greatly appreciated. Thanks for
the help.
--
JT

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
Error Handling Dave M. Excel Programming 1 August 31st 05 07:15 PM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
error handling off?? Tom Ogilvy Excel Programming 0 August 19th 04 04:31 PM
Error Handling bw Excel Programming 3 June 20th 04 06:43 PM


All times are GMT +1. The time now is 03:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"