Starting access using a Batch File

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Is it possible to open access (front-end, secured database) using a batch file? Does anyone have a sample code that I could refered to?

Thank you,

Daniel
 
Hi Daniel,

Here's an example. See "Startup command-line options" in help for more.

"C:\program files\microsoft office\office10\msaccess.exe"
"d:\folder\folder\DB.mdb" /wrkgrp "\\server\share\DB.mdw"
 
Tim,

Never heard of it. Could you elaborate a bit more (I'm new to the batch world). The IT guy out my way told me that a batch file would save me a lot of hassel over the long run, and from what I've seen so far I think he's right. I don't know if anyone else might have any input on the subject?!

Using the batch file I can easily update one parameter (the release of the database) and it updates it for all my users in the batch file instead of having to edit the properties of each user's shortcut.

Anyways, Tim if you could explain it a bit more it would be greatly appreciated!

Thank you for the help,

Daniel
 
Hi Daniel,

You could try passing the /c switch to the command interpreter when you
invoke the batch file, e.g.

cmd.exe /c "C:\folder\folder\LaunchIt.bat"
 
Never heard of it. Could you elaborate a bit more (I'm new to the
batch world).

WScript.exe and CScript.exe are scripting hosts that come free with
Windows. The first runs in the GUI and the second has a console interface.
You can use pretty much any language you like with them -- VBScript and
JScript are built in, but there are PERL extensions too. The advantage is
that you can access real Windows structures and, for an Access programming
group, the language is very close to VBA!
Is it possible to open access (front-end, secured database)
using a batch file? Does anyone have a sample code that I
could refered to?

You can use the Shell function (I don't do this much so treat with a great
deal of caution!):-

Option Explicit

Dim strCommand ' all variables are variants!
Dim dblProcID

strCommand = "c:\office\programs\msaccess.exe " & _
"d:\folder\folder\DB.mdb " & _
"/wrkgrp \\server\share\DB.mdw"

dblProcID = WScript.Shell(strCommand)

MsgBox "Access should be running now!"

' Finished


Alternatively you could just carry out whatever you wanted to do all in the
vbs file:-

' try to open an Access workspace and use it to

dim dbe ' access dbengine
dim wks ' jet workspace
dim db ' database


Set dbe = CreateObject("DAO.DBEngine.36")
dbe.SystemDB = "d:\programming\mytemp.mdw"

Set wks = dbe.CreateWorkspace("AddEric", _
"practice", "practice password", 2)

set db = wks.OpenDatabase("d:\programming\vbscript\practise.mdb")

' manual error trapping here
on error resume next

' do a command
db.Execute _
"INSERT INTO Test (FullName, Age) " & _
"VALUES ('Eric', 3.5)", _
128 ' dbFailOnError

if err.number <> 0 Then
' there was a problem
MsgBox "The update did not work!"
WScript.Quit 3

End if

' normal exit
WScript.Quit 0


Well, that should give you the idea. Best wishes


Tim F
 
Back
Top