I got some cool code to allow the user to compact the database from a command button on the Main Menu. It worked fine until recently.
I have included the code which looks at a table to see what the last compact date was, and if over 30 days proceeds to compact the database by closing it, compacting and re-opening it. It did allow the user to manually run it by skipping the checking of the Compact table date!
Sub CheckCompactDate()
Dim dbs As Database
Dim rst As Recordset
' Get default Workspace.
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tlkCompactDate"
With rst
' Loop through recordset
Do Until .EOF
If Date - !Compactdate > 30 Then
.Edit ' open the file for editing
!Compactdate = Date
.Update 'update the record
'call the compact db function
Call Compactdb
Else
'do nothing
End If
.MoveNext 'go to the next record
Loop
.Close ' close recordset
End With
End Sub
Function Compactdb()
On Error GoTo Compactdb_Err
SendKeys "%(TDC)", False
Compactdb_Exit:
Exit Function
Compactdb_Err:
MsgBox Error$
Resume Compactdb_Exit
End Function
All I get now is a beep from the computer, the date inserted into the table and nothing else.
I should mention that since writing the code, I removed the Menu and Toolbar from the form and maximized through a docmd.maximise. Any connections?
Any advice is better than none!
Angelique
I have included the code which looks at a table to see what the last compact date was, and if over 30 days proceeds to compact the database by closing it, compacting and re-opening it. It did allow the user to manually run it by skipping the checking of the Compact table date!
Sub CheckCompactDate()
Dim dbs As Database
Dim rst As Recordset
' Get default Workspace.
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tlkCompactDate"
With rst
' Loop through recordset
Do Until .EOF
If Date - !Compactdate > 30 Then
.Edit ' open the file for editing
!Compactdate = Date
.Update 'update the record
'call the compact db function
Call Compactdb
Else
'do nothing
End If
.MoveNext 'go to the next record
Loop
.Close ' close recordset
End With
End Sub
Function Compactdb()
On Error GoTo Compactdb_Err
SendKeys "%(TDC)", False
Compactdb_Exit:
Exit Function
Compactdb_Err:
MsgBox Error$
Resume Compactdb_Exit
End Function
All I get now is a beep from the computer, the date inserted into the table and nothing else.
I should mention that since writing the code, I removed the Menu and Toolbar from the form and maximized through a docmd.maximise. Any connections?
Any advice is better than none!
Angelique