Solved

MDB location on Local PC or Server

Posted on 2004-09-20
5
374 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
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
type of query 11 42
Access Crosstab Query with Multiple Values 4 32
Access 2003 query lost it's only join 7 27
Turn off MS Access Default=0 for Numerics 6 25
In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

773 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