Stuck with my code

Nothing we have discussed relates to saving the record on the current form. Record changes are saved when you tab to the next record, or hit Enter, or close the form, or save it otherwise from VBA code.
 
Ok So how do i stop it from Saving When its an incorrect Key or even delete the Record if its invalid?

Joshua
 
Well, the code we've discussed is in the click event of a button. Is the button in the Header portion of the form? If so, that's why your changes are being saved, because you're clicking outside of the current record (which is another case of when changes get saved). If that's the problem, you could move the button to the Detail section. That still wouldn't prevent changes from being saved for any of the above reasons, whether or not they clicked the button. Are they supposed to always click the button whenever they enter something on the form, or just in certain cases?
 
Are they supposed to always click the button whenever they enter something on the form, or just in certain cases?
Well there only to enter that form when they need to create there account and this buttons already in the Details Tab.

Joshua
 
Ok, but it's still going to save changes to the record unless they are cancelled.
You could do something like this:

Code:
Dim ValidUpdate as Boolean

Private Sub Form_Open(Cancel As Integer)
    ValidUpdate = True
End Sub

Private Sub Form_AfterUpdate
    ValidUpdate = False
End Sub

Private Sub Form_Unload(Cancel as Integer)
    If Not ValidUpdate Then
       If MsgBox("Your entry has not been validated. " & _
                 "To close the form without saving your changes, click Ok", vbOKCancel) <> vbOK Then
           Cancel = True
       End If
    End If
End Sub

Then in your button click code, when the entries have been validated:

Code:
        MsgBox "Thank You for Registering"
        ValidUpdate = True
        DoCmd.Close
        DoCmd.OpenForm "Form1"
 

Users who are viewing this thread

Back
Top Bottom