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

MS Access Shortcut - Launch via Visual Basic

Status
Not open for further replies.

bkf7911

MIS
Mar 20, 2007
83
0
0
US
I have an access database that I use a shortcut to enter, due to security being in a separate .mdw file. How can i launch this database through the shortcut using VB? It doesn't have to be able to login to the menu screen, just open the DB to the prompt where the user can login. I keep receiving an error when using the following.

strAccessDB = "C:\Documents and Settings\User1\Desktop\WS - WFH\Database1.mdb.LNK"
Set objShell = CreateObject("WScript.Shell")
objShell.Run "msaccess """ & strAccessDB & """", 1, False
Set objShell = Nothing

Its trying to read ONLY the first location in the "Target" field of the shortcut, and gives me the error that its an unrecognized database format.
 
You could use the target from the shortcut properties, or it may be suitable to use the shortcut:

Code:
strAccessDB = "C:\Documents and Settings\User1\Desktop\WS - WFH\Database1.mdb.LNK"
Set objShell = CreateObject("WScript.Shell")
objShell.Run """" & strAccessDB & """", 1, False
Set objShell = Nothing

You do not need the 'msaccess' bit as that is already part of the shortcut.


 
I'd use the actual location of the .mdb instead of the .lnk file.

Also, you generally will need to specify the location of the MSAccess.exe--especially if you have two versions of Access.
--Jim
 
Remou, i wasn't able to have it open the shortcut or the target of the shortcut. It kept opening MSAccess.exe within access, and seeing it as an error, or seeing it as a DataAccess page and giving me an error on open.

Jsteph, I wouldn't be able to use the actual MDB because the database uses workgroup security and the user has to access the .mdb and the .mdw file for the DB to work correctly.

ShortcutTarget:"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "C:\Documents and Settings\User1\Desktop\WS - WFH\Database1.mdb" /WRKGRP "C:\Documents and Settings\User1\Desktop\WS - WFH\Security.mdw"

Anyway..... i found/modified something in MS help pages that's working for me. It is as follows, should you ever need.

Thanks

Dim accObj As Access.application
Dim Msg As String
Dim application As String
Dim dbs As String
Dim workgroup As String
Dim user As String
Dim password As String
Dim cTries As Integer
Dim x

' This is the default location of Access
application = "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE"
' Use the path and name of a secured MDB on your system
dbs = "C:\Documents and Settings\User1\Desktop\WS - WFH\Database1.mdb"
' This is the default workgroup
workgroup = "C:\Documents and Settings\User1\Desktop\WS - WFH\Security.mdw "
'user = "Admin" ' Use a valid username
'password = "Mypassword" ' and correct password

x = Shell(application & " " & Chr(34) & dbs & Chr(34) & " /nostartup /user " & user & _
" /pwd " & password & " /wrkgrp " & Chr(34) & workgroup & Chr(34), vbMinimizedFocus)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top