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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Start an Access DB

Status
Not open for further replies.

puforee

Technical User
Oct 6, 2006
741
US
I am trying to use VBS to start some applications, one of which is an Access DB. I am a novice with VBS and this code was used for another project. I borrowed the part I thought might work for me. Here is my code so far:

Dim Fn,Fn1,FSO
dim sQuote
sQuote = chr(34)


Fn="\System Access Tracker" 'Change value here
Set FSO = CreateObject("Scripting.FileSystemObject")
s=FSO.GetAbsolutePathName(".")
s=s & Fn
Fn1= s &".mdb"
'Fn1 =sQuote & Fn1 & sQuote
msgbox Fn1
Wscript.Echo "File "&Fn1
Set sh= CreateObject("WScript.Shell")
returnVal = sh.Run (Fn1)

The msgbox equals d:\Profiles\jjs8542\Desktop\System Access Tracker.mdb. This is the true path to the Access DB.

I commented out the sQuote line but the code will not start the DB with or without it. There are no error messages when the code runs.

Thaks,
 
Since you path contains spaces you'll need to add additional quotes around them.

something like this may work.

returnVal = sh.Run("msaccess.exe " & AddQuotes(Fn1))

Function AddQuotes(strInput)
AddQuotes = Chr(34) & strInput & Chr(34)
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Simply comment out the following line in your code:
'Fn1 =sQuote & Fn1 & sQuote

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK guys,

Here is the current code with your suggestions:

Dim Fn,Fn1,FSO
dim sQuote
sQuote = chr(34)


Fn="\System Access Tracker" 'Change value here
Set FSO = CreateObject("Scripting.FileSystemObject")
s=FSO.GetAbsolutePathName(".")
s=s & Fn
Fn1= s &".mdb"
msgbox Fn1
Wscript.Echo "File "&Fn1
Set sh= CreateObject("WScript.Shell")
returnVal = sh.Run ("msaccess.exe "& addQuotes(Fn1))



msgbox shows D:\Profiles\jjs8542\Desktop\System Access Tracker.

I still does not start Access or the DB.

Suggestions?
 
Sorry for the typo:
In your originally posted code, remove the comment (') from the following line:
'Fn1 =sQuote & Fn1 & sQuote

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If you took the output generated and copied it into the Run command does it work?

Code:
Dim Fn,Fn1,FSO
dim sQuote
sQuote = chr(34)


Fn="\System Access Tracker" 'Change value here
Set FSO = CreateObject("Scripting.FileSystemObject")
s=FSO.GetAbsolutePathName(".")
s= s & Fn
Fn1= s &".mdb"
' msgbox Fn1
' Wscript.Echo "File "&Fn1
Set sh= CreateObject("WScript.Shell")
InputBox "","", "msaccess.exe "& addQuotes(Fn1)
' returnVal = sh.Run ("msaccess.exe "& addQuotes(Fn1))

Function AddQuotes(strInput)
    AddQuotes = Chr(34) & strInput & Chr(34)
End Function 
[code]

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
dm4ever, I finally got it, with your excellent help. Here is the final script that works. Note I moved everything to a more convenient place to work and renamed the DB to test. I commented some items out to make it streamlined. I will leave them there for future trouble shooting. I also added in a bit of code so the name of the VBS file is the same as the DB. This makes it easier to use for multiple items.

Thanks again for all your help.

Dim Fn,Fn1,FSO,s
dim sQuote
dim scriptName : scriptName=WScript.ScriptName
sQuote = chr(34)

Fn=Left(scriptName, Len(scriptName)-4)&".mdb"

Set FSO = CreateObject("Scripting.FileSystemObject")
s=FSO.GetAbsolutePathName(".")
s=s & "\"
s=s & Fn
Fn1 =sQuote & s & sQuote
' msgbox Fn1
'Wscript.Echo "File "&Fn1
Set sh= CreateObject("WScript.Shell")
'InputBox "","", "msaccess.exe "&(Fn1)
returnVal = sh.Run ("msaccess.exe "&(Fn1))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top