Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MDB location on Local PC or Server

Posted on 2004-09-20
5
Medium Priority
?
380 Views
Last Modified: 2006-11-17
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

0
Comment
Question by:TonyWootton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 1000 total points
ID: 12101062
there is code at http://www.mvps.org/access/api/api0003.htm that determines what drives are available on a PC and what type they are ... one of the types is Local so if the drive type the file is on is not Local you know it is on another machine. Would you like some help modifying the code?

Steve
0
 
LVL 39

Expert Comment

by:stevbe
ID: 12101133
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
0
 
LVL 39

Expert Comment

by:stevbe
ID: 12101136
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
0
 

Author Comment

by:TonyWootton
ID: 12101438
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
0
 

Author Comment

by:TonyWootton
ID: 12101479
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question