PDA

View Full Version : Message Box Will Not Go Away



JoanneA
01-15-2014, 09:59 AM
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

Aussiebear
01-15-2014, 10:09 PM
Is the missing End If just a typo?

jonh
01-16-2014, 02:48 AM
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.

mancubus
01-16-2014, 02:50 AM
and what is "Exit_Command32_Click" and why do you resume it?

SamT
01-16-2014, 02:59 PM
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,