xenou
MrExcel MVP
- Joined
- Mar 2, 2007
- Messages
- 16,836
- Office Version
- 2019
- Platform
- Windows
I've created this function - does anyone know of any alternatives or see any improvements? The purpose would be to pass the db path to DBEngine(0) for a compact and repair, so I don't want to open the database, just find out if its in use. One thought that comes to mind is that perhaps the compact and repair would just return an error and I can trap that error?
(parameter f is the mdb file -- assume there is a module scope FileSystemObject available. So the purpose of this function is to see if there is an ldb or laccdb file of the same base name as the database in the same folder as the database)
ξ
(parameter f is the mdb file -- assume there is a module scope FileSystemObject available. So the purpose of this function is to see if there is an ldb or laccdb file of the same base name as the database in the same folder as the database)
Code:
[COLOR="Navy"]Private Function[/COLOR] LockFileExists(ByRef f [COLOR="Navy"]As[/COLOR] Object) [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Boolean[/COLOR]
[COLOR="Navy"]Dim[/COLOR] s(1) [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] i [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="SeaGreen"]'//Derive base name, without extension[/COLOR]
s(0) = FSO.GetAbsolutePathName(f.Path)
i = Len(FSO.GetExtensionName(f.Path))
s(0) = Left(s(0), Len(s(0)) - i - 1)
[COLOR="SeaGreen"]'//Check for lock files - .ldb/.laccdb[/COLOR]
s(1) = s(0) & ".ldb"
[COLOR="Navy"]If[/COLOR] FSO.FileExists(s(1)) [COLOR="Navy"]Then[/COLOR]
LockFileExists = True
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Function[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
s(1) = s(0) & ".laccdb"
[COLOR="Navy"]If[/COLOR] FSO.FileExists(s(1)) [COLOR="Navy"]Then[/COLOR]
LockFileExists = True
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Function[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Function[/COLOR]
ξ
Last edited: