trueharted
Programmer
I am attempting to utilize a compacting database I found online. The code loops through two fields in a table. One field is the path and the other field is the name of the database to be compacted. There are multiple databases to be compacted. The code works great on databases that are not password protected. All of my databases are password protected with the same password. Can anyone tell me how to pass the password in this code? I know how to do it with OpenDatabase, but not with OpenRecordset. Please let me know if you need more detail. Thanks ahead of time.
Public Function Compact_Database()
'===========================================================
'The Timer event runs this code every minute.
'It compares your system time with the StartTime
'variable. When they match, it begins compacting
'all databases in the DBNames table.
'===========================================================
Dim StartTime As String
' Set this variable for the time you want compacting to begin.
StartTime = "10:00 PM"
' If StartTime is now, open the DBNames table and start compacting.
If Format(Now(), "medium time"
= Format(StartTime, _
"medium time"
Then
Dim RS As DAO.Recordset, DB As DAO.Database
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames"
On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder"
& "\" & RS("DBName"
' Create a new name for the compacted database.
' This example uses the old name plus the
' current date.
NewDBName = DBName 'Left(DBName, Len(DBName) - 4)
NewDBName = NewDBName & " " & Format(Date, "MMDDYY"
& ".mdb"
DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes
End If
End Function
-----------
Sincerely,
gricks
Public Function Compact_Database()
'===========================================================
'The Timer event runs this code every minute.
'It compares your system time with the StartTime
'variable. When they match, it begins compacting
'all databases in the DBNames table.
'===========================================================
Dim StartTime As String
' Set this variable for the time you want compacting to begin.
StartTime = "10:00 PM"
' If StartTime is now, open the DBNames table and start compacting.
If Format(Now(), "medium time"

"medium time"

Dim RS As DAO.Recordset, DB As DAO.Database
Dim NewDBName As String, DBName As String
Set DB = CurrentDb()
Set RS = DB.OpenRecordset("DBNames"

On Error Resume Next
RS.MoveFirst
Do Until RS.EOF
DBName = RS("DBFolder"


' Create a new name for the compacted database.
' This example uses the old name plus the
' current date.
NewDBName = DBName 'Left(DBName, Len(DBName) - 4)
NewDBName = NewDBName & " " & Format(Date, "MMDDYY"

DBEngine.CompactDatabase DBName, NewDBName
RS.MoveNext
Loop
' Close the form, and then close Microsoft Access
DoCmd.Close acForm, "CompactDB", acSaveYes
RS.Close
DoCmd.Quit acSaveYes
End If
End Function
-----------
Sincerely,
gricks