Ordering Validation Functions

dynamix

Registered User.
Local time
Today, 23:11
Joined
Feb 9, 2005
Messages
38
I have like 2 or 3 validation techniques on one field, most of which are triggered by clicking the Save button. One of these techniques checks to see if data in the field is present, the other is to format the date with a msgbox dd/mm/yyyy.

But also, on the Save button click function there is a confirmation box to proceed or cancel the save.

However this method doesn't work for me..If I try saving the record without anything in validated field, a box comes up saying 'Must enter data here bla bla', so you click OK, but then the command button one runs too saying its been saved.. I don't want it to save the record if the validation has popped up basically.. Heres the code:

Private Function ConfirmEntries() As Boolean
'Purpose: Checks whether entries have been made in the
'following textboxes and displays a message for any null
'values or empty boxes

If IsNull(Me.Start_Date) Then
MsgBox "Please enter member Start_Date"
Start_Date.SetFocus
ConfirmEntry = True
Exit Function
End If
If IsNull(Me.Exp_Date) Then
MsgBox "Please enter member Exp_Date"
Exp_Date.SetFocus
ConfirmEntry = True
Exit Function
End If


End Function



Private Sub cmdSaveDetails_Click()

Dim mbrResponse As VbMsgBoxResult
Dim str As String
DoCmd.RunCommand acCmdSaveRecord
ConfirmEntries
mbrResponse = MsgBox("You have chosen to add a subscription to member: " & Me.F_Name & ".", vbInformation + vbOKCancel, "Confirm Choice")

If mbrResponse = vbOK Then
'if OK was clicked
mbrResponse = MsgBox("Confirmed choice " & Me.F_Name & " " & Me.L_Name & ".", vbInformation + vbOKCancel, "Confirm Choice")
Else
'if Cancel was clicked
MsgBox "Subscription Cancelled"
End If
End Sub
This was a tough one to explains :S..

Thanks!
 
You've asked this question before and the answer is still the same - you need to move your validation code to the BeforeUpdate event of the form. That is the only place that you can reliably cancel the update. Otherwise, you have to figure out ALL the ways that Access will automatically save your data and place code in those events. Do yourself a favor and use the correct event.
 
Code:
Private Function ConfirmEntries() As Boolean
        'Purpose: Checks whether entries have been made in the
        'following textboxes and displays a message for any null
        'values or empty boxes

    [B]ConfirmEntries = True                    'Set Default Case[/B]

    If IsNull(Me.Start_Date.Value[B]) or Me.Start_Date.Value = ""[/B] Then
        MsgBox "Please enter member Start_Date"
        Start_Date.SetFocus
        ConfirmEntry = [B]False[/B]
        Exit Function
    End If

    If IsNull(Me.Exp_Date.Value[B]) or Me.Exp_Date.Value = ""[/B] Then
        MsgBox "Please enter member Exp_Date"
        Exp_Date.SetFocus
        ConfirmEntry = [B]False[/B]
        Exit Function
    End If
End Function



Private Sub cmdSaveDetails_Click()
    Dim mbrResponse As VbMsgBoxResult
    Dim str As String

    [B]If ConfirmEntries Then
        DoCmd.RunCommand acCmdSaveRecord
    Else
        Exit Sub
    End If[/B]

    mbrResponse = MsgBox("You have chosen to add a subscription to member: " & Me.F_Name & ".", vbInformation + vbOKCancel, "Confirm Choice")

    If mbrResponse = vbOK Then
        'if OK was clicked
        mbrResponse = MsgBox("Confirmed choice " & Me.F_Name & " " & Me.L_Name & ".", vbInformation + vbOKCancel, "Confirm Choice")
    Else
        'if Cancel was clicked
        MsgBox "Subscription Cancelled"
    End If
End Sub

First problem is, you want to continue only if both the boxes are filled in. The way your code was set up, it continues if they're not filled in (ConfirmEntry = True). Second problem, you're checking the conditions after you already save them? This doesn't really make sense to me. Save only if the conditions are true.
 
Last edited:
Oh.. I see, that works :S..

How about if I wanted an alert box popping up if they have missed a field out and pressed the save button?

So 'You must enter a value in F_Name" etc..
 

Users who are viewing this thread

Back
Top Bottom