Very frustrated with BeforeUpdate event

  • Thread starter Thread starter NoviceNana
  • Start date Start date
N

NoviceNana

Hi I'm mainly a lurker and I've been searching through the list for a
few days trying to find an answer to my very frustrating automatic
save problem.

I have a form with a subform in it. In the subform there are 4
required text fields and 4 number fields. I have a Save button that I
want to use EXCLUSIVELY to save the record. Next to it is a Close
button that I'd like to use EXCLUSIVELY to close the form. I do not
want the record to be saved when the close button is hit. I just want
the form to close.

I know I have to write some code in the BeforeUpdate event of the
subform. I tried just (Me.Undo) but that prevents saving even when the
save button is pushed... not helpful. I've tried about a million
other codes that I've found online or tried to come up with and
nothing is working. If anybody has any additional help/codes I would
greatly appreciate it. Again I just want a form where the save
button is the ONLY thing that saves the record. The record should not
save when the form is closed or after any other updates are made.

I look forward to your responses!!
 
Hello, I am often frustrated as well, but you have come to the right place
for help. There is probably a better way than this, but ... Put an unbound
text on the form, we'll call it txtText. Then put code behind on_click of
the save button

Private sub save_onlclick
me.txtText.value = "1"
rest of code
Exit sub

For the close button:
Private sub close_onclick
Select Case txtText
Case 1
docmd.close
Case 0
me.undo
docmd.close
End Select
Exit sub

You will have to put me.txtText.value = "0" in the forms open event, and
make txtText so small it will not be visible. I hope this helps you.
 
If the save button is on subform then you can create a private boolean
variable (blnSave) that will take true value when the user click the
save button and will remain false if the user doesnt click it. So on
before update event of your subform you could check the value of the
variable and undo changes.
If blnSave=False Then
Me.Undo
End if
On current event you reset the value of the variable to false.
 
I have a form with a subform in it. In the subform there are 4
required text fields and 4 number fields. I have a Save button that I
want to use EXCLUSIVELY to save the record.

Which record are you talking about. The sub-form record. If you have lots
of records in the sub-form, you likely don't want to torture, and nag
the person into an insane asylum because every time they move to
enter more data into the sub-form, they will have to hit save.

It is just too much for the users. Likely you should re-consider.

I mean, if you design a car, and try to open he door, do you
need a prompt to them come up and say "do you really
want to open the door?

or, how about you turn the key to start the car...and then the
car prompts you - do you really want to start the car!!

And worse in this nag police attitude is when you turn the
car off, it will ask you - Do you really want to turn the
car off?

Really, if a user is going to close a form, then why are they
closing the form? Because they are done!! Why not let
ms-access do its job..and save for you. Your users will
love you for this.

And, if a user is moving on tot he next record, then again
why is the user moving...well...because they are done!!!

Implied saves is the new user friendly mantra in software
today, and we are disposing away with more and more
dialogs....

Thank goodness software people don't design cars!!!

However, you also need to clarify what record in the subform
you are talking about, and clearly that when save it pressed,
are you going save the current sub-forms record, or the main
record? Remember, each form has ONLY ONE RECORD that
you can save at a time. Each form deals with ONE RECORD
at a time.

Also, remember, as soon as the cursor moves into the sub-
form, ms-access saves the main form (so, even un-do is gone
at this point). The reason for this is relatonal data, and the
fact that you can't add a sub-form record untill the main forms
reocrd is saved....
 
Thanks everybody for all your help! I tried Greg S's option and it
worked perfectly. I didn't read the end of the post so I just set "0"
as the default value for the text box, but I'll go back and set it as
part of the Open Form event. Also I added code to the BeforeUpdate
event just make to sure it did in fact "undo" if the text box =0.
Thanks again!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top