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

18 responses on “Launch/Open an MS Access Database Using a VBScript

  1. David

    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!

    1. admin Post author

      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.

  2. Adam

    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”

    1. admin Post author

      I’m afraid i do not. Furthermore, it would defeat the purpose of such security if you could merely change it using standard coding. Your best bet would bet to post your question in a good forum. Give as much detail as possible, explain what you are trying to accomplish, and even the why you are trying to do it and people will offer you solutions to your question.

  3. Dan

    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

  4. Kelly

    Hello. Thank you for this code. Would this be used for a 2013 Access db? I’m having a hard time getting this to work.

    1. Daniel Pineault Post author

      Yes, it should work without issue. I created it back in 2008, so that would mean it was working with Access 2007 and beyond.

      What problem are you having?

  5. Carl

    Thanks and here is a novice question as I’m new to all of this stuff. Where exactly do you put this code? I work for a company and have been trying to use access to help with our data. We have a network but I’m not an admin. Thanks.

    1. Daniel Pineault Post author

      Create a new txt file using Notepad.
      Copy/Paste the vbscript for the site into the txt file.
      Save it. You can give it the name you’d like.
      Go and rename the txt file from YourFileName.txt to YourFileName.vbs

      You now have a vbscript.
      You can continue to edit it with any standard text editor.
      Double-click on it to run it.

  6. sandy

    This works if you’re using a network drive or one drive.
    it does not works for sharepoint location.
    Any help pleae

    1. Daniel Pineault Post author

      I wish I could help, but I do not use SharePoint (it couldn’t do what we needed when we looked into it and from a database perspective the list limitations just don’t make sense). Your best bet is to ask your question in a forum (utteraccess.com is an excellent one!) and someone there with direct SharePoint experience may be able to better guide you.

      Best of luck to you.

  7. kim

    can you take me one step further and tell me where to put the script and how it actually gets distributed to users? Sorry I am novice with the VBA

    1. Daniel Pineault Post author

      You create a text file and copy/paste the code. Alter the paths to what your paths are and save. Then change the file extension to .vbs

      Now you can give a copy to each user, when they double-click it should launch your database.