Solved

MDB location on Local PC or Server

Posted on 2004-09-20
5
372 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
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
stevbe earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now