Link to home
Start Free TrialLog in
Avatar of TonyWootton
TonyWootton

asked on

MDB location on Local PC or Server

Although I realise that CurrentDb.Name can be used to determine the directory location of the MDB being run, I would like to determine whether a location for any given MDB is actually located on a users PC or on a Server to which that PC may be connected. Certainly C: or D: are most likely to indicate a location on a PC and a path starting with "\\" will probably indicate a server-based path.

It would, however, be helpful to know of a method that would be more rigorous and give an accurate answer, for example, for an MDB located on a server but which is actually being run in that context as if it were a PC.

Although this is not often a matter of crucial importance, an answer might be very useful in determining whther or not a given file can be accessed by means of a UNC path. The answer may well be obvious if you already know it but the allocated points will be generous and will be given to the first respondant whose answer is clear and unambiguous.

Thanks, Tony

ASKER CERTIFIED SOLUTION
Avatar of stevbe
stevbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stevbe
stevbe

ok ... here goes ... parse the first 2 characters from CurrentDB.Name and pass to GetUNCPath, if the return is 0 then it is a network drive, else it is a local drive ...

example call ...

?IsLocal(Left$(CurrentDB.Name,2))


the api declaration below needs to go at the top of a module...

Private Declare Function WNetGetConnection Lib "mpr.dll" Alias _
        "WNetGetConnectionA" (ByVal lpszLocalName As String, _
        ByVal lpszRemoteName As String, cbRemoteName As Long) As Long


'this code needs to be placed in the same module as the api declaration above...

Public Function IsLocal(strDriveLetter As String) As Boolean
    Dim Msg As String, lngReturn As Long
    Dim lpszLocalName As String
    Dim lpszRemoteName As String
    Dim cbRemoteName As Long
    lpszLocalName = strDriveLetter
    lpszRemoteName = String$(255, Chr$(32))
    cbRemoteName = Len(lpszRemoteName)
    lngReturn = WNetGetConnection(lpszLocalName, lpszRemoteName, _
                                       cbRemoteName)
   
    If lngReturn = 0 Then
        IsLocal = False
    Else
        IsLocal = True
    End If
End Function

Steve
oops ...

parse the first 2 characters from CurrentDB.Name and pass to GetUNCPath

should be

parse the first 2 characters from CurrentDB.Name and pass to IsLocal

Steve
Avatar of TonyWootton

ASKER

Hi Stevbe,

Many thanks for this reference. I actually looked at the MVPS site before I asked the question, but I must have missed it. I glanced at the link and I'm sure that it will be most helpful - certainly much more rigorous than relying on "\\" prefixing the UNC.

The question was posed in the context of writing a utility MDB for installing/upgrading Access clients because it VB scripts were either too simplistic, not re-usable or otherwise unsatisfactory. Something like InstallShield is overkill, but a small access utility (where potential users need Access to run their applicationsanyway) could be just what was needed.

I have written such a utility (I should say, written a working prototype) and it has proved to be both useful and effective. However, there are a number of ways in which it could be usefully enhanced and determining the local/server location of an MDB was part of a train of thought.

Many thanks for your response and also for your offer of coding help, even though I can deal with that aspect of the development.

Regards, Tony
Hi Steve,

Thanks also for your later comments; I'm sorry I took so long replying, but I thought my further explanation of context might be of interest.

Regards, Tony