Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2013
    Posts
    53

    Unanswered: Compact & Repair Database VBA

    Hello All! Back again for leveraging your expertise Have the following vba code that retrieves a compile error. Any suggestions on how to structure it so that the Compact and Repair runs when the user exits the db?

    Code:
    Private Sub cmdExitAccess_Click()
        
        Dim intResponse As Integer
        
        intResponse = MsgBox( _
        prompt:="Are you sure you want to exit Access now?", _
        buttons:=292, _
        Title:="Exit Access")
            If intResponse = 6 Then
        Quit
            End If
            
        DoCmd.CloseDatabase acCmdCompactDatabase
        
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Quote Originally Posted by VBAnewbie View Post
    Hello All! Back again for leveraging your expertise Have the following vba code that retrieves a compile error. Any suggestions on how to structure it so that the Compact and Repair runs when the user exits the db?

    Code:
    Private Sub cmdExitAccess_Click()
        
        Dim intResponse As Integer
        
        intResponse = MsgBox( _
        prompt:="Are you sure you want to exit Access now?", _
        buttons:=292, _
        Title:="Exit Access")
            If intResponse = 6 Then
        Quit
            End If
            
        DoCmd.CloseDatabase acCmdCompactDatabase
        
    End Sub
    1. CloseDatabase is not among the methods of the DoCmd object (i.e. Docmd.CloseDatabase does not exist in Access). See: DoCmd Object [Access 2003 VBA Language Reference]

    2. The command to close Access is: Application.Quit.

    3. About compacting a database when closing it, see: General: Why CompactCurrentDatabase doesn't work from code
    Have a nice day!

  3. #3
    Join Date
    Jan 2013
    Posts
    53
    Much appreciated, thanks!

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •