Validating Using Before Update Event

spenz

Registered User.
Local time
Tomorrow, 06:20
Joined
Mar 26, 2009
Messages
61
If IsNull(Me.TransactionNameID) Or IsNull(Me.Credit) Or
Or IsNull(Me.Rate) Or IsNull(Me.EmployeeID) Then

If MsgBox("No value entered, do you want to continue exiting without saving?.", vbYesNo) = vbYes Then
Cancel = True
End If

End If

Good day to all! I'd like to ask for help regarding before update event and closing my form. first of all, the only exit button i have on this form is the command button i made earlier named cmdclose; and had a vba code attached to the on click event like this:

DoCmd.Close acForm, "frmReceivableT", acSaveNo
DoCmd.Requery ""

So at first i'm glad that the code itself works, it does not actually save the data when some of the needed data is not filled out yet. But, the problem lies to that when i press close and the messagebox appears, even if i choose "No" as an answer to the message box it still closes the form and as a result it appears to save the current incomplete data. But what i want is, if i press "No" i should be able to get back to the form and fill out the needed fields in order to pass from the validation rule i implemented earlier. Pressing "Yes" has no issue because it does exactly what i want it to do. Cancel saving data and closing the form. it's just that "No" that's causing me the problem. Any suggestions and opinions are welcome. Thanks in advance
 
Here is an example
Code:
If MsgBox("Do you want to save?"", vbYesNo + vbQuestion) = vbNo Then
DoCmd.Close acForm, "frmReceivableT", acSaveNo
    DoCmd.Requery ""
    Else
[COLOR=Red]*save code goes here[/COLOR]
    End If
 
Private Sub cmdClose_Click()

If MsgBox("Do you want to save?", vbYesNo + vbQuestion) = vbNo Then
DoCmd.Close acForm, "frmReceivableT", acSaveNo
DoCmd.Requery ""

Else
If IsNull(Me.Credit) Then
MsgBox "Credit Field is empty"
DoCmd.CancelEvent
End If

End If

End Sub

Hi rainman thanks for the help, iam not sure if i'm getting your instruction right.. what i did is basing from your example, i've deleted my before update event code and pasted it instead on the onclick event on my command button control which is named cmdclose. The result has a little bit of improvement than my problem before but still it's not what i wanted. so here is the result of my test: When i click "Yes" it asked me, Do you want to save? if i choose yes then the validation rule appears indicating a hint to fill it up but if i choose "No" instead it will close the form and still save the data which is i'm avoiding.

What i want is when i chooose "Yes" it activates my validation code which it does right now and then if i choose "No" it should close the form without saving the incomplete data. Thanks again
 
This code worked before correct?

DoCmd.Close acForm, "frmReceivableT", acSaveNo
 
This code worked before correct?

DoCmd.Close acForm, "frmReceivableT", acSaveNo

Yes it did worked before or even with the new code you've suggested. Only problem is when i choose "No" it still ended up saving the incomplete data. it seemed to me that the acSaveNo argument has nothing to do with saving the data or not.
 
You're exactly right, spenz! The acSaveNo has nothing to do with the saving of a record! It tells Access not to save any changes made to the design of the form! Replace it with something like Me.Undo.
 
You're exactly right, spenz! The acSaveNo has nothing to do with the saving of a record! It tells Access not to save any changes made to the design of the form! Replace it with something like Me.Undo.

okay but still i can't replace it with me.undo because the only choices were 1.acSaveNo 2.acSaveYes 3.acSavePrompt and if i put me.undo there i'm just receive a compile error.

I also have docmd.CancelEvent below which isn't really canceling because when i click "No" it still saves the incomplete data.
 
this doesnt work?
Code:
If MsgBox("Do you want to save?", vbYesNo + vbQuestion) = vbNo Then
    me.undo
DoCmd.Close acForm, "frmReceivableT", acSaveNo
    DoCmd.Requery ""
    
Else
        If IsNull(Me.Credit) Then
        MsgBox "Credit Field is empty"
        DoCmd.CancelEvent
        End If
   
End If
    
End Sub
 
this doesnt work?
Code:
If MsgBox("Do you want to save?", vbYesNo + vbQuestion) = vbNo Then
    me.undo
DoCmd.Close acForm, "frmReceivableT", acSaveNo
    DoCmd.Requery ""
    
Else
        If IsNull(Me.Credit) Then
        MsgBox "Credit Field is empty"
        DoCmd.CancelEvent
        End If
   
End If
    
End Sub


Yes Thanks rainman mate, That Actually Worked! I also tried changing docmd.CancelEvent into me.undo but it didn't any good. Thanks again! Rep For you ;)
 

Users who are viewing this thread

Back
Top Bottom