File Name

M

Martin

Hello,

I have a simple bit of code to get the file name of the database:

*************Start Code*****************
Public Function CheckDatabaseName()
Dim CurrentFileName As String
CurrentFileName = Application.CurrentDb.Name
End Function
**************End Code******************

This file is on a network and the letter of the drive is always returned
with this code. I need the server name to be retuned not the drive letter
i.e. my J: drive is one of my shared drives but I would like the server name
which is Dstrt on xxxxxx (as you would see in Explorer).

Can anyone help? I have been looking for days now and have given up!

Thanks

Martin
 
D

Douglas J. Steele

What you get returned by that call depends on how you open the application.
If you're clicking on a shortcut that uses a mapped drive, you'll always get
the mapped drive.

Take a look at http://www.mvps.org/access/api/api0003.htm at "The Access
Web" to determine the UNC associated with a mapped drive.
 
J

Joe Williams

Doug and Martin,

I saw this code and applied it into my app. one follow up question: What
would be the code to extrract just the server name from the string that is
returned?

Example, the function on the Access Web returns \\SERVER\SHARENAME. how can
I extract just SERVER and not the \\ or sharename?

Thanks

Joe
 
D

Douglas J. Steele

Function GetServerOnly(UNC As String) As String
' Doug Steele, Microsoft Access MVP
' Assuming UNC is \\server\sharename,
' this function returns server.
' Otherwise, it returns an empty string ("")
Dim intPos As Integer
Dim strServer As String

strServer = ""

If Left$(UNC, 2) = "\\" Then
intPos = InStr(3, UNC, "\", vbBinaryCompare)
If intPos > 0 Then
strServer = Mid$(UNC, 3, intPos - 3)
End If
End If

GetServerOnly = strServer

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top