Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can someone help me refine this VB Script - it works but not well 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
A gentleman named Ben O'Hara was kind enough to post some VBScript code to help automate an Access upgrade from Access97 to Access2000. His response was to my post on the Access VBA forum.

Here is the working code which I run by double clicking the file named Convert.vbs in the Windows file explorer. I have not used VBScript before but have used Access VBA extensively.

Some questions follow the code.

************************** BEGIN CODE ********************
Option Explicit

Dim WshShell
Dim FSO
Dim strFromDir
Dim strConvertDir
Dim Folder
Dim File

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = WScript.CreateObject("Scripting.FileSystemObject")

'strFromDir="C:\databases\"
'strFromDir="B:\References Project\Test\"
strFromDir="B:\Refere~1\Test\"
strConvertDir=strFromDir & "Convert\"

set Folder= FSO.GetFolder(strFromDir)

for each File in Folder.Files

WSHShell.Run "C:\Progra~1\Micros~3\Office\Msaccess.exe " & File.Path & " /convert " & strConvertdir & file.name

next

wscript.quit
************************** END CODE **********************

1. This attemps to convert every file in the directory. Can I filter for the extension mdb?

2. Is there a function to convert Long File Names with embedded spaces into the old style FileNa~x notation so the code doesn't break?

3. How do I handle number 2 above for File names with an embedded space?

4. Can I invoce the vbs file from a bat file or from Access? If so, how do I do that?

5. How do I pass parameters into my vbs file?

Any help, suggestions or code samples would be greatly appreciated! Have a great daY!

 
Sorry, I forgot one question. Can I trap errors and send them to a log file so the process continues? I would like to automate this, but I need to know which ones have compilation errors, etc. so I can handle them later.

Thanks again for any help you can give me!

 
1)
Code:
If Ucase(Right¤(File.Name,4)) = ".MDB" Then
...
2)
Code:
File.ShortPath
3) See 2)
4) from a .bat file:
Code:
cscript.exe YourScript.vbs Parm1 Parm2 ...
5)
Code:
Set myArgs = WScript.Arguments
For i = 0 To myArgs.Count - 1
  WScript.Echo myArgs(i)
Next
6)
Code:
On Error Resume Next
...
If Err.Number <> 0 Then
  WScript.Echo &quot;Error #&quot; & Cstr(Err.Number) & &quot; &quot; & Err.Description
  Err.Clear
End If

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top