Close button problem

wrightie

Registered User.
Local time
Today, 09:49
Joined
Jun 11, 2009
Messages
22
I am hoping that someone can guide me in the right direction here because I am wandering around lost! :confused:
What I have is a Main form and within that a subform. The users input into these forms and the data goes straight into 2 tables.
On the Main form I have a Save Record button and a Close button. Now the problem I have is that if the user accidentally starts inputting and then decides to close the form the record still gets saved.
Is there a way to check whether there is data in the main form and the subform – if there isn’t close the form as normal but if there is ask the user if they want to save or close without saving ?
cheers
Wrightie
 
I would try validation rules in the text boxes. That should pull up an error that you can trap.
 
IMPORTANT INFO TO KNOW -

When you move off of the main form, into the subform, the main form's data is saved automatically. When you move off the subform back to the main form, the subform's data is saved automatically. So, depending on what validation you are looking for, it can be someone complex as to how you have to go about it (for example, if you find you want to cancel one or the other form information).

The form's Before Update event can be used to validate the current form's information. You can set a
Cancel = True
to stop the update from happening. But it will only stop the current form's update from happening.
 
Hey thanks for the replys. I'm still stuck though, but I'm trying.
I've got the code below but like you say Bob as soon as you get as far as the subform it looses focus and when you close the Mainform it still saves the data.
If you only input data on the mainform (current form) then it works perfectly. It actually doesn't matter if only some of the data gets saved. I just need it to ask the question, "are you sure?" and then either delete the mainform data or the subform data. Is there anyway it can be done ?

thanks
wrightie

Code:
Private Sub cmdClose_Click()
If Dirty = False Then
DoCmd.Close acForm, "Journal_Entry_Form"
DoCmd.OpenForm "Switchboard"
Exit Sub
End If
 
If Me.Dirty = True Then
If MsgBox("Are you sure you want to quit without posting?", vbYesNo) = vbYes Then
'delete current record
DoCmd.RunCommand acCmdDeleteRecord
 
'then close form and return to switchboard
DoCmd.Close acForm, "Journal_Entry_Form"
DoCmd.OpenForm "Switchboard"
Exit Sub
End If
End If
  
End Sub
 
Your forms are bound to queries that is why it is saving.

If you can record the ID of the record on the main form, you can create a delete query that will delete the record, from the main form, when you click yes
 
Hey Ray,

I've taken your advice.
Many thanks
wrightie
 

Users who are viewing this thread

Back
Top Bottom