PDA

View Full Version : Button Not Working after Message Box



ajames420
08-27-2007, 01:33 PM
I put in what I thought was a quick fix for a message box to appear if the user only enters a Actual Fine and does not define the type of fine.

The message box works fine but it if pops up then you enter the fine and hit add record it does nothing. Help please!!!

Code:

Dim Msg, Style, Title, Response

If Missort_Fine = 0 And Dup_ID = 0 And Paid_Early = 0 _
& Priority = 0 And COD = 0 And Pkg_Type = 0 And Unmanifested = 0 Then
Msg = "You must have at least one field with a fine amount!" ' Define message.
Style = vbOK + vbCritical ' Define buttons.
Title = "Postal Fine Entry" ' Define title.
' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then ' User chose Yes.
DoCmd.CancelEvent
Missort_Fine.SetFocus ' Perform some action.
Else
DoCmd.GoToRecord , , acNewRec
HubID.SetFocus
End If
End If


Edited 28-Aug-07 by geekgirlau. Reason: insert vba tags

geekgirlau
08-27-2007, 08:53 PM
This code needs to be part of the BeforeUpdate event of the form, and to cancel saving the record if no fine type has been entered, use:

Cancel = True


Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim Msg, Style, Title, Response


If Missort_Fine = 0 And Dup_ID = 0 And Paid_Early = 0 _
& Priority = 0 And COD = 0 And Pkg_Type = 0 And Unmanifested = 0 Then

Msg = "You must have at least one field with a fine amount!" ' Define message.
Style = vbOK + vbCritical ' Define buttons.
Title = "Postal Fine Entry" ' Define title.

' Display message.
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then ' User chose Yes.
Missort_Fine.SetFocus ' Perform some action.
Cancel = True
Else
DoCmd.GoToRecord , , acNewRec
HubID.SetFocus
End If
End If
End Sub



Personally, I wouldn't be allowing the user to move on until they'd corrected the problem - if they've left out a required field, display the message, set the focus to the control and then cancel the record update.

By the way, please make sure you use the VBA tags when posting code - just select the text and click on the VBA button.

ajames420
08-28-2007, 05:24 AM
Thank you for the help.

As for your comment " Personally, I wouldn't be allowing the user to move on until they'd corrected the problem - if they've left out a required field, display the message, set the focus to the control and then cancel the record update."

They don't have to have all of the fields filled out. At least one has to filled out to describe the fine type. That is why I have to wait until they hit the update record button. I am not sure of any other way to to it other then this.

And I will hit the tag button next time. Thanks again

Anthony