Cancel button on form

Bilal

Registered User.
Local time
Today, 21:13
Joined
Sep 30, 2013
Messages
64
what would i write in the onclick private sub of my 'btnCancel'
i need it to do a number of things depending on whether there is data entered in the form fields or whether its completely empty, is there is data being entered in some fields and the cancel button is clicked it should ask whether the user wants to lose all current data as a msgbox, or if there is completely no data in any of the fields and the cancel button is clicked it shoud take me make to the main form where the rest of my buttons work, which is "inmode normal"
 
If the form's record source is bound to a table or query, look in the MS-Access Help-file under "Dirty".
If the form is unbound then cycle to all the textbox-controls in the form by using For .. Each, checking if the is something written in the textbox-control.
 
Something like this?

Code:
Private Sub btnCancel_Click()

If Me.Dirty Then

 If Not (Me.NewRecord) Then
   If MsgBox("Would You Like To Save The Changes To This Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save Changes to Record ???") = vbNo Then
    Me.Undo
   End If
 Else
   If MsgBox("Would You Like To Save This New Record?", vbQuestion + vbYesNo + vbDefaultButton1, "Save This New Record ???") = vbNo Then
    Me.Undo
   End If
 End If

Else

 DoCmd.OpenForm "MainFormName"

End If

End Sub
Just replace MainFormName with the actual name of your Form.

Linq ;0)>
 
yup thanks, looks good enough :)
if it dont work as intended i can tamper around with it, as long as i got something to work around
 

Users who are viewing this thread

Back
Top Bottom