Launch/Open an MS Access Database Using a VBScript

Have you ever tried to make a shortcut to launch/open an MS Access database and had an error returned because the Target string was too long? Or do you simply need more control/flexibility from your launching routine. In that case, a VBScript is the ideal way to go. Below is the most basic format that the VBScript can take. Simply alter the Script Variables, Save and execute!

I have made the following as flexible as possible so it can open simple database files, as well as security enabled database. It is simply a question of assigning values to the Script Variables or not.

I truly hope this helps you out!

'*******************************************************************************
'Date:		2008-05-27
'Author:	Daniel Pineault / CARDA Consultants Inc.
'		http://www.cardaconsultants.com
'Copyright:	You are free to use the following code as you please so long as
'		this header remains unaltered.
'Purpose:	Launch the specified access database
'Revision:	2008-05-27   Initial Release
'*******************************************************************************

	Dim sAcc
	Dim sFrontEnd
	Dim sSec
	Dim sUser
	Dim objShellDb
	Dim sComTxt
 
'Script Configuration Variable
'*******************************************************************************
	'Specify the Fullpath and filename of the msaccess executable
	sAcc = "C:\Program Files\Microsoft Office\OFFICE11\msaccess.exe"
	'Specify the Fullpath and filename of the database to launch
	sFrontEnd = "D:\Main\My Documents\TestDb.mdb"
	'If your database is secured by an mdw file specify it below, otherwise
	'leave its value blank
	sSec = "C:\Databases\Security.mdw"
	'If your database is secured by an mdw file and you want to specify the
	'username to use specify it below, otherwise leave its value blank
	sUser = ""
 
 
'*******************************************************************************
'*******************************************************************************
'You should not need to edit anything below this point
'*******************************************************************************
'*******************************************************************************

 
'Launch database
'*******************************************************************************
	Set objShellDb = CreateObject("WScript.Shell")
	'Build the command to launch the database
	sComTxt = chr(34) & sAcc & chr(34) &_
		  " " & chr(34) & sFrontEnd & chr(34) 
	if isNull(sSec)=False AND sSec<>"" Then
		sComTxt = sComTxt & " /wrkgrp " & chr(34) & sSec & chr(34)
	End if
	if isNull(sUser)=False AND sUser<>"" Then
		sComTxt = sComTxt & " /user " & sUser
	End if
	objShellDb.Run sComTxt 'Launch the database

Tags:

6 Comments to “Launch/Open an MS Access Database Using a VBScript”

  1. Thank you for this post. I been trying to find out how-to accomplish exactly this and haven’t been able to find a clear and concise example, well, until I came across your excellent website.

    Thank you! Thank you! Thank you!

  2. Dan you are a legend

    I needed this for my citrix environment and it works a treat.

    Thanks alot man.

    • I don’t know about being a legend, but I like a lot of other people out here (online) just enjoy being able to share our knowledge and help others out! If I can pass along some of what I have learnt the long and hard way so that others in similar situations can be spared the time and frustrations, and given a leg up on their work, it is my pleasure to do so.

      Thank you for your feedback. I truly appreciate knowing that this site is useful and worth my energies.

  3. Dan that is a very gracious attitude and I hope it rubs off onto more people.

    Do you have any knowledge on how to set the macro security level in access to low using your script?

    I have previously been able to set the security through other means (shown below), but I’m not sure how to combine that functionality with your script..

    Set oAccess=Createobject (“Access.Application”)
    oAccess. automationsecurity=1
    oAccess.opencurrentdatabase “Database.mdb”

  4. Fan-Tastic. I have an awful old MS Access DB that needs to be running on my server, but sometimes it chokes, so I needed a nice script to kill it and restart it.

    This started it up perfectly. Thank you!

    -dan

Leave a Reply









Spam protection by WP Captcha-Free