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

Error when opening file

Status
Not open for further replies.

darkhat01

IS-IT--Management
Apr 13, 2006
144
US
I am trying to open a access data base and I cannot open it with a vbscript... Here is the the script that I am using. Any ideas?

Thanks so much for any help.

Darkhat01



Set Sh = CreateObject ("WSCript.Shell")
prog = "C:\Program Files\Microsoft Office\Office\MSACCESS.EXE"
db = "\\server1\ab-c Production 081706\Core_Database\Reporting DB\Glue.mdb"
Sh.Run Chr(34) & prog & Chr(34) & " " & db & " /wrkgrp "

 
What's the error you're getting? Are you trying to just load that file in Access on the machine running the script? My VBS experience is primarily with ASP but in most cases (unless you wanted Access to start on the machine executing the script) I would use an ADODB.RecordSet object to connect to the Access database for reading/writing within the VBScript.
 
I am getting this error:

Line: 4
Char: 1
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)

Now this is the correct location...

All I need is for the Glue.mdb to open up in access. Any ideas?

Thanks,

Darkhat01
 
Assuming it can find \\server1 you might try using the short name of the next folder, which is probably something like ab-cPr~1 in case it's choking on the spaces in the string used for the file path.
 
So how do I use a UNC path with VBS?

Thanks...
 
I've not had any trouble using network paths with VBS. You could try using the explicit IP address for server1 instead of the friendly name. Also you could try putting quotes in around the folder names that have spaces:
Code:
db = "\\server1\""ab-c Production 081706""\Core_Database\""Reporting DB""\Glue.mdb"
 
You're problem is use use chr(34) to capture for spaces in prog but just ignore them in db.

I just tried UNc manually and it works fine.

Sh.Run Chr(34) & prog & Chr(34) & " " & Chr(34) & db & Chr(34) & " /wrkgrp "

[yinyang] Tranpkp [pc2]
 
or you can use this:
Code:
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet  = CreateObject("ADODB.Recordset")
dbfile = "c:\your_path\your_database.mdb"  

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
              "Data Source=" & dbfile & ";"
 
Thanks.. I am going to try these ideas... you guys are great...

Thanks again...
 
This is the code that works...

There is now a new question... The Access database has a password on it, how can I have the script add the password to it. I thought that it was something like ;pwd=Pa$$word
Pa$$word being the password you choose in the database? Any ideas...

Thanks....


Set Sh = CreateObject ("WSCript.Shell")

'Microsoft Access location
prog = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"

'Database location
db = "\\server1\ab-c Production 081706\Core_Database\Reporting DB\Glue.mdb"

'Command line running
Sh.Run Chr(34) & prog & Chr(34) & " " & Chr(34) & db
 
Perhaps this ?
Sh.Run Chr(34) & prog & Chr(34) & " " & Chr(34) & db & Chr(34) & " /pwd Pa$$word"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
with the code that i listed above, you do not need prog = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"

that listing that i posted, will open your database using access program. i'm not sure about the password though. i tried it as phv suggested, and i can't get it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top