(re-sending because my original reply hasn't appeared)
J. Freed said:
I have a program that reads the contents of MSysObjects from different
mdb's
and copies them into another mdb. Since the program will be reading
several
thousand mdb's it has to run unattended into the night. Problem: when it
hits
a password-protected file it stops to wait for someone to type in a
password/cancel. Is there a way to programmatically detect
password-protected
files without actually opening them? TIA.......
You could attempt to open each database in code and trap the error if you
can't. For example,
Dim db As DAO.Database
Dim strDBPath As String
On Error Resume Next
' Demo test of unsecured DB.
strDBPath = "C:\Users\Dirk\Documents\Unsecured.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay, so close it.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If
' Demo test of DB with password.
strDBPath = "C:\Users\Dirk\Documents\Passworded.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If
' Demo test of DB with User-Level Security.
strDBPath = "C:\Users\Dirk\Documents\ULS_Secured.mdb"
Err.Clear
Set db = Application.DBEngine.OpenDatabase(strDBPath, , True)
If Err.Number <> 0 Then
Debug.Print "Can't open '" & strDBPath & _
"'. Error was " & Err.Number & ": " & Err.Description
Else
' Opened okay.
Debug.Print "Opened '" & strDBPath & "'"
db.Close
End If
The above code can be expected to display the following lines in the
Immediate window:
Opened 'C:\Users\Dirk\Documents\Unsecured.mdb'
Can't open 'C:\Users\Dirk\Documents\Passworded.mdb'. Error was 3031:
Not a valid password.
Can't open 'C:\Users\Dirk\Documents\ULS_Secured.mdb'. Error was 3033:
You do not have the necessary permissions to use the
''C:\Users\Dirk\Documents\ULS_Secured.mdb' object. Have your system
administrator or the person who created this object establish the
appropriate permissions for you..