Find User Path

S

Sandy

Hi, I hope you can assist me.

I need to create a module that reads the path the user used to open the
database file and return a message to them stating that they opened the path
via a shortcut if that is the case.

One step better would be: If the user accesses the database via a shortcut,
prevent them from opening the database and re-direct to the correct path.

Any help with this would be much appreciated!

Sandy
 
M

Morten Snedker

On Thu, 9 Dec 2004 12:39:03 -0800, "Sandy"

I don't think there is any regular way to determine if Access is
opened via shortcut or not.

If the the shortcuts are made by developer you could use the /cmd
command line parameter with the shortcut. Then you could use this
parameter to determine if Access was opened via shortcut.

However, it is not fool proof, since the user can change or re-make
the shortcut, in which the parameter could be omitted.

Regards /Snedker
 
S

Sandy

Snedker,

Thank you for your reply. I actually did find something that worked and I
will share it here in case anyone else ever needs it. :)


This code I placed in a Module and named the Module DIRECTORIES
'******************** Code Begin ****************
'Code courtesy of
'Terry Kreft & Ken Getz
'
Function CurrentDBDir() As String
Dim strDBPath As String
Dim strDBFile As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
End Function
'******************** Code End ****************

I have a Splash form that is set to open on Startup. This form runs the
following code on open:
'.........................Start Code........................................

Private Sub Form_Open(Cancel As Integer)
Dim SearchString, SearchChar, Shortcut
Dim Path As String
Path = CurrentDBDir()

SearchString = Path ' String to search in.
SearchChar = "C:" ' Search for "C:".

' A textual comparison starting at position 4. Returns 6.
Shortcut = InStr(1, SearchString, SearchChar, 1)

If Shortcut > 0 Then
MsgBox "The shortcut you are using was created improperly." & Chr(13) & _
"Please access the database via this path:" & Chr(13) & "S:\Associate
Information\Manager Information\Operations PTP 5.0.mdb" & Chr(13) & _
"Once in the database, you may select the Create Shortcut option to create a
proper shortcut to this database.", vbCritical, "Access Not Allowed"
DoCmd.Quit
Else
Exit Sub
End If

End Sub
'.......................................End
Code..................................
 
D

Douglas J. Steele

Sorry, but that doesn't indicate whether the database was opened from a
shortcut or not.

All that code does is indicate whether the current database is located on
the C: drive or not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top