Find Current Database name in VBA (1 Viewer)

PhilHoad

New member
Local time
Today, 21:39
Joined
May 1, 2014
Messages
2
As part of a printout I'd like to use print.debug in Access VBA:banghead: to display the Current Database name. Pls could anyone help.

Thanks,
Phil (New member
 

MarkK

bit cruncher
Local time
Today, 13:39
Joined
Mar 17, 2004
Messages
8,187
Welcome to the forum

In Access you can get the current database using the CurrentDb function, and a DAO.Database has a .Name property. Combining these facts, you can do . . .
Code:
Debug.Print CurrentDb.Name
Hope this helps,
 

PhilHoad

New member
Local time
Today, 21:39
Joined
May 1, 2014
Messages
2
Many thanks, that certainly helps - I now have a few follow on questions:
1) Can I display just the name and just the file path seperately on different Debug.print lines?
2) Is CurrentDb an object viewable in the Object Browser?

Thanks again:D
 

namliam

The Mailman - AWF VIP
Local time
Today, 22:39
Joined
Aug 11, 2003
Messages
11,695
1)
Currentproject.path
currentdb.name
Dir(currentdb.name)
Left(currentdb.name, len(currentdb.name) - Len(dir(currentdb.name)))
left(Currentdb.Name, instrrev(currentdb.Name, "\"))

2)
Currentdb isnt in the object browser, no, but you probably found that already.
 

MarkK

bit cruncher
Local time
Today, 13:39
Joined
Mar 17, 2004
Messages
8,187
1) Yes, as posted by namliam, and in addition . . .
Code:
Private Sub Test19347601748()
    With CreateObject("Scripting.FileSystemObject")
        Debug.Print .GetParentFolderName(CurrentDb.name)
        Debug.Print .GetFileName(CurrentDb.name)
    End With
End Sub
2) Yes of course CurrentDb is in the object browser. CurrentDb is a function exposed by the Access.Application object that returns a DAO.Database object.
 

Users who are viewing this thread

Top Bottom