Get Database Path Accessed

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
 
P

Panteliadis Babis

in acc2000 or later easy:
getDataBasepath= CurrentProject.Path
MsgBox getDataBasepath' Or do whatever you want with the string
 
N

Nikos Yannacopoulos

Hmm... this will return the path the project is stored in, not how it
was opened!

Sandy,

I'm afraid for all I know there's no way to tell what you're asking -
but I'd love to know how if I'm wrong!

Nikos
 
B

Bas Cost Budde

I need to create a module that reads the path the user used to open
But... why do you want to interfere with how users use their operating
system? Does something break when a user opens the database through a
shortcut?
 
V

Vincent Verheul

Hello Sandy,

Maybe not exactly what you asked - but it looks like you don't want people
to open the database directly and do things they're not supposed to do. An
alternative approach might be to use an Access MACRO in stead of a shortcut:

- Create a macro in Access that opens the form that you like the users to
see first
- Make sure that the Access window is not maximised, and that you can see
your desktop
- Drag & Drop the macro from Access to your desktop
- Have a look at the MACRO shortcut using Wordpad or any text editor: you'll
see the link information

Now also create a macro called 'Autoexec' in Access and include an action
that will tell the user not to open the database directly, but use the MACRO
shortcut instead and subsequently close Access.

Hope this helps,
Vincent
 
S

Sandy

Thank you all for your assistance :)

I was able to find a procedure that returns the directory string. From that
I did a search on the string for C:

The problem we were having was that users were improperly creating shortucts
(drag and drop) to their desktops. They didn't realize that they were no
longer accessing the live database.. bad, bad, bad. LOL

Anyway, here's the solution:

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..................................

Thanks again!

-- Sandy
 

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