Jim DeMarco
Jdemarco at hshhp.org
Wed Dec 10 07:20:10 CST 2003
John,
Why are you using using On Error Resume Next when the FileSystemObject contains a FileExists method? This way you can have meaningful error handling if necessary.
<snip>
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(strFileName) Then
fs.CopyFile strFileName, strDestDir
CopyFile = True
End if
</snip>
Jim DeMarco
Director Product Development
Hudson Health Plan
-----Original Message-----
From: John W. Colby [mailto:jcolby at colbyconsulting.com]
Sent: Wednesday, December 10, 2003 7:27 AM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] CmdRunApp Help
Erwin,
Why not post code as I did?
John W. Colby
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Erwin Craps -
IT Helps
Sent: Wednesday, December 10, 2003 2:38 AM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] CmdRunApp Help
Hi John
Why using the filesystemobject and not the regular VBA commands?
Faster?
Erwin
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of John W. Colby
Sent: Tuesday, December 09, 2003 9:11 PM
To: Access Developers discussion and problem solving
Subject: RE: [AccessD] CmdRunApp Help
why don't you just do it from within Access? If the filesystem object
is accessible, reference it. Then:
Function CopyFile(strFileName As String, strDestDir As String) As
Boolean On Error GoTo Err_CopyFile Dim fs As FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
'On Error Resume Next
'if the file doesn't exist, ignore the error
fs.CopyFile strFileName, strDestDir
CopyFile = True
Exit_CopyFile:
On Error Resume Next
Set fs = Nothing
Exit Function
Err_CopyFile:
MsgBox Err.Description, , "Error in Sub basUtils.CopyFile"
Resume Exit_CopyFile
Resume 0 '.FOR TROUBLESHOOTING
End Function
Sub DeleteFile(strFileName As String)
On Error GoTo Err_DeleteFile
Dim fs As FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'if the file doesn't exist, ignore the error
fs.DeleteFile strFileName
Exit_DeleteFile:
On Error Resume Next
Set fs = Nothing
Exit Sub
Err_DeleteFile:
Select Case Err
Case 0 '.insert Errors you wish to ignore here
Resume Next
Case Else '.All other errors will trap
Beep
MsgBox Err.Description, , "Error in Sub basUtils.DeleteFile"
Resume Exit_DeleteFile
End Select
Resume 0 '.FOR TROUBLESHOOTING
End Sub
Sub RenameFile(strFileName As String, strNewName As String) On Error
GoTo Err_RenameFile
Dim fs As FileSystemObject
Dim f As File
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(strFileName)
f.Name = strNewName
Exit_RenameFile:
On Error Resume Next
Set f = Nothing
Set fs = Nothing
Exit Sub
Err_RenameFile:
Select Case Err
Case 0 '.insert Errors you wish to ignore here
Resume Next
Case Else '.All other errors will trap
Beep
MsgBox Err.Description, , "Error in Sub basUtils.RenameFile"
Resume Exit_RenameFile
End Select
Resume 0 '.FOR TROUBLESHOOTING
End Sub
'.Comments :
'.Parameters:
'.Created by: John W. Colby
'.Created : 12/5/2002 9:29:43 PM
Sub CreateDir(strPath As String)
On Error GoTo Err_CreateDir
Dim fs As FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
'if the file doesn't exist, ignore the error
fs.CreateFolder strPath
Exit_CreateDir:
On Error Resume Next
Set fs = Nothing
Exit Sub
Err_CreateDir:
Select Case Err
Case 0 '.insert Errors you wish to ignore here
Resume Next
Case Else '.All other errors will trap
Beep
MsgBox Err.Description, , "Error in Sub basUtils.CreateDir"
Resume Exit_CreateDir
End Select
Resume 0 '.FOR TROUBLESHOOTING
End Sub
John W. Colby
www.ColbyConsulting.com
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Gowey Mike W
Sent: Tuesday, December 09, 2003 3:03 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] CmdRunApp Help
Hello all,
I have within my database a call to run a batch program that takes a
file that resides on one of our Network servers and copies it to our
local server and renames it to a text file. I than take that text file
and import it into a table.
My question is, is there a way to call the batch program and have it run
in the background or run minimized. Right now it works but the dos
window comes up over the top of the database and does the copy and
rename in other words runs in the foreground.
I have a progress meter that comes up that I would like the user to see
rather than the ugly little black dos window.
Thanks in advance for any advice.
Mike Gowey, MCSA, A+
Team Leader - SRCI
Information Systems & Services Division
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
***********************************************************************************
"This electronic message is intended to be for the use only of the named recipient, and may contain information from Hudson Health Plan (HHP) that is confidential or privileged. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or use of the contents of this message is strictly prohibited. If you have received this message in error or are not the named recipient, please notify us immediately, either by contacting the sender at the electronic mail address noted above or calling HHP at (914) 631-1611. If you are not the intended recipient, please do not forward this email to anyone, and delete and destroy all copies of this message. Thank You".
***********************************************************************************