Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current file

Status
Not open for further replies.

abe6162

Programmer
Sep 7, 2004
24
US
How can I tell the name of the current file I am working with.

I would like to know the name of the Access file I am current working on. I want to do this in VBA

Thanks!
 
These four Function are in my GeneralFunction module that is in almost every db I create. The second and third will be of direct interest to you.

Code:
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> 0 Then
    If Forms(strFormName).CurrentView <> 0 Then
        IsLoaded = True
    End If
End If
End Function

Function DatabaseNameAndPath() As String
Dim db As Object
Set db = CurrentDb()
DatabaseNameAndPath = CurrentDb.Name
End Function

Function DatabaseMappedPath() As String
' Returns all to the left of the last '\'
' Ie \\Server\Path\   from   \\Server\Path\Name.mdb
DatabaseMappedPath = Left(DatabaseNameAndPath, InStrRev(DatabaseNameAndPath, "\"))
End Function

Public Function FileExists(strServerPathFileName As String) As Boolean
Dim strServerPath As String
Dim strFile As String

strServerPath = Left(strServerPathFileName, InStrRev(strServerPathFileName, "\") - 1)
strFile = Mid(strServerPathFileName, Len(strServerPath) + 2)

With Application.FileSearch
    .NewSearch
    .LookIn = strServerPath
    .SearchSubFolders = False
    .FileName = strFile
    .MatchTextExactly = True
    .FileType = 1               ' msoFileTypeAllFiles
       
'    If .Execute() = 0 Then      ' File does not exist
'        FileExists = False
'    Else
'        FileExists = True
'    End If
    FileExists = .Execute
End With

End Function


'ope-that-'elps.



G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 

I can use your other functions also. Thanks so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top