Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MDB location on Local PC or Server

Posted on 2004-09-20
5
Medium Priority
?
381 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

963 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