Jolio81
asked on
Code to allow MS Access database to determine whether it's being run from a network
Is there a catch-all way for an Access database frontend to detect whether it's being opened from a network location (mapped to a drive or not) versus the user's hard drive?
I want to keep the frontends off the network so that multiple users don't use the same copy, and to reduce traffic.
I know about Currentdb.name, and I know what drive letters we use for network locations, but I want something that will work anywhere.
I want to keep the frontends off the network so that multiple users don't use the same copy, and to reduce traffic.
I know about Currentdb.name, and I know what drive letters we use for network locations, but I want something that will work anywhere.
A great question!
I would think there is a windows API call that would need to be made. Only the OS will know if it's a local or mapped/unc connection.
Let me see what I can find out...
Jim.
I would think there is a windows API call that would need to be made. Only the OS will know if it's a local or mapped/unc connection.
Let me see what I can find out...
Jim.
Looks like you can use the GetDriveType() function, or GetDrivePath().
Let me see what I can work up.
Jim.
Let me see what I can work up.
Jim.
I put all of my current version front ends in a specific folder on my server, something like:
C:\DatabaseApplications\
Then I have some code in the Timer event (TimerInterval = 1000) of my Splash form of my applications which checks to see whether the CurrentProject.Path matches that path. If so, it displays a message indicating that the application cannot be run from the server and shuts down.
Private Sub Form_Timer()
If CurrentProject.Path = "C:\Users\dale.fye\Documen ts\Work\Ac cess" Then
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
C:\DatabaseApplications\
Then I have some code in the Timer event (TimerInterval = 1000) of my Splash form of my applications which checks to see whether the CurrentProject.Path matches that path. If so, it displays a message indicating that the application cannot be run from the server and shuts down.
Private Sub Form_Timer()
If CurrentProject.Path = "C:\Users\dale.fye\Documen
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
My Timer event should have read:
Private Sub Form_Timer()
If CurrentProject.Path = "C:\DatabaseApplications\" Then
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
But I like the GetDriveType function call and may try that. Wonder if that requires modification for 64 bit systems or Office (x64)?
Private Sub Form_Timer()
If CurrentProject.Path = "C:\DatabaseApplications\"
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
But I like the GetDriveType function call and may try that. Wonder if that requires modification for 64 bit systems or Office (x64)?
Note that you need to pass a root spec, ie. IsNetworkDrive("C:\")
and not just a letter.
Jim.
and not just a letter.
Jim.
Using Jim's IsNetworkDrive function, you could change my example code to:
Private Sub Form_Timer()
If IsNetworkDrive(CurrentProj ect.Path) Then
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
Private Sub Form_Timer()
If IsNetworkDrive(CurrentProj
MsgBox "cannot run from Server, copy application to desktop before running"
Application.Quit
End If
End Sub
A better or at least easier approach may be to force the application to launch from the desktop and not a server location. I have a batch file that copies my frontend each time the app is launched to the local machine. This keeps people from running the frontend from the server and when I need to do an update to the front end I only have to change it in one place.
cls
echo ************************** ********** ********
echo Update Local Copy
echo This will update your machine with my App
echo from the file server. If this is NOT what
echo you want to do, press CTRL and C now.
echo ************************** ********** ********
pause
echo Copying file... Please wait
REM if not exist c:\myapp md c:\my app
copy j:\apps\myapp0\myapp.mdb c:\myapp
cls
echo **************************
echo Update Local Copy
echo This will update your machine with my App
echo from the file server. If this is NOT what
echo you want to do, press CTRL and C now.
echo **************************
pause
echo Copying file... Please wait
REM if not exist c:\myapp md c:\my app
copy j:\apps\myapp0\myapp.mdb c:\myapp
ASKER
Great! Thanks Jim!
To add a bit of robustness, I modified your function a bit:
Public Function IsNetworkDrive(strPath As String) As Boolean
strPath = Left(strPath, 2)
IsNetworkDrive = (GetDriveType(strPath) = 4) Or (strPath = "\\")
End Function
To add a bit of robustness, I modified your function a bit:
Public Function IsNetworkDrive(strPath As String) As Boolean
strPath = Left(strPath, 2)
IsNetworkDrive = (GetDriveType(strPath) = 4) Or (strPath = "\\")
End Function
if left(currentdb.name,3)<> "C:\" then