Consulting

Results 1 to 5 of 5

Thread: Message Box Will Not Go Away

  1. #1

    Message Box Will Not Go Away

    Hello,I have an Access 2007-2010 database that on one of the forms, there is a "Finish" button. The form is set up to select from dropdown boxes and/or enter amounts for different categories of things. If you have entered data in the form and you click on the "finish" button then the form should close. If you did not enter/choose any drop down data then when you click the "finish" button a message box should come up. I have this all working except that when there is an error and the message box comes up, when you click ok it does not go away, ever. You have to cntrl break to get past the message box. Here is the code for the "finish" button.
    Private Sub Command32_Click()
    On Error GoTo Err_Command32_Click 
       If Me.Dirty Then 
    Me.Dirty = False 
       DoCmd.CloseExit_Command32_Click: 
       DoCmd.Close "EODDailyCalc", acDefault 
       Exit Sub
    Err_Command32_Click: 
       MsgBox "You did not complete the form, nothing will be saved" 
       Resume Exit_Command32_Click
    End Sub
    Thanks in advance for the help!JoanneA

  2. #2
    Moderator VBAX Guru Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    4,997
    Location
    Is the missing End If just a typo?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    I never use labels but I expect the line "Resume Exit_Command32_Click" could be causing it to loop?

    Anyway, since there are other ways of closing a form and saving data you might want to use form events instead. e.g.

    Dim Edited As Boolean
    
    Private Sub Form_AfterUpdate()
        Edited = True
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        If Not Edited Then _
            Cancel = MsgBox("You did not complete the form, nothing will be saved.", _
                vbQuestion + vbYesNo, "Continue without save?") = vbNo
    End Sub
    This way even if the user tries to close the application the message will get displayed and the application wont close if the form's unload event is cancelled.

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    and what is "Exit_Command32_Click" and why do you resume it?
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    There is not enough info to tell what you are trying to do, so here is what you are actually doing

    Private Sub Command32_Click() 
        If Me.Dirty Then 'Set Dirty to false
            DoCmd.Close "EODDailyCalc", acDefault 
    On Error programatically click  Exit_Command32 button
    'No End If error occurs here
        End Sub
    Try this
    Private Sub Command32_Click() 
        On Error Goto Err_Command32_Click 
        If Me.Dirty Then 
            Me.Dirty = False 
            DoCmd.Close 
            DoCmd.Close "EODDailyCalc", acDefault 
            Exit Sub 
    End If
    
    Exit Sub
    
    Err_Command32_Click: 
            MsgBox "You did not complete the form, nothing will be saved" 
            Exit_Command32_Click 
        End Sub
    Always put "Option Explicit" at the top of all code pages. You can use VBA's Tools menu >> Options to do this automatically,
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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