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!

Launch MS Access via Shortcut using VB 1

Status
Not open for further replies.

bkf7911

MIS
Mar 20, 2007
83
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.
 

What would happen if you would drop the .LNK from your strAccessDB?

Code:
strAccessDB = "C:\Documents and Settings\User1\Desktop\WS - WFH\Database1.mdb[red].LNK[/red]"[blue]
strAccessDB = Left(strAccessDB, Len(strAccessDB) - 4)[/blue]
Set objShell = CreateObject("WScript.Shell")
objShell.Run "msaccess """ & strAccessDB & """", 1, False
Set objShell = Nothing

Have fun.

---- Andy
 
I think the problem is that i'm using workgroup security for the database, and as a result the Target in the shortcut addresses three actions: 1) it opens MS Access.exe. 2) It opens the database. 3) It references the workgroup security file, .mdw.

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