access 2010. VBA to Undo changes in previous form

Hi,

A bit of a tricky one here, so here goes.

I have two forms, lets call them, form1 & form2.
I enter data in form1, click next and form2 opens (form1 remains open but hidden).
Click next on form2 and all the data from form1 and form2 is then saved into various tables. Fine, this is exactly what i want.

My problem is, that if a user decides to abort the process and clicks cancel on form2, i use Me.Undo to undo form2 changes, close form2 and close form1 (from form2). However, I cannot seem to undo the changes that were made in form1 when closing it from form2.

Any suggestions please?
andrewpiconnectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
The only way I can see is to use a late bind. This means you don't bind your forms to the tables, and the save button actually does the save (using VBA.).

Typical Access design is an early bind where the forms record source is set to a table for query. The moment the focus is moved to another form, form 1's data is written. The undo functionality is then lost. If the form is not bound (and is hidden) the fields remain populated, and are either lost when closed, or written using VBA from a save button - typically by creating a INSERT INTO statement.


Kelvin
0
andrewpiconnectAuthor Commented:
Hi Kelvin,

Hmmm, i was dreading that comment as there are 40+ fields in form1.

I was toying with the idea of using a recordsetclone on form1 and comparing this with the saved record but getting this to fire from form2 on close as expakined above. To be honest though, i got myself lost in the process a little hence here i am asking for help.

If the only sure way to do this is as you suggest, then i will have to do it that way i guess.

I will keep the question open a little while in case someone comes with an alternative but if not then you have first dibs on the points.

Many thanks
0
hnasrCommented:
' undo Form2
Me.Undo
'undo Form1
Forms("Form1").Undo
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Jeffrey CoachmanMIS LiasonCommented:
Yes, there are many things at  play here.
Including if the data in the forms is related and how.

In other words, if you create a customer in form 1 and then create an order in form 2, you cannot then delete the customer.

So perhaps your logic here needs to be rethought.
Why would a user have to enter data in form 2 before they realized that the data in form 1 is not needed...

So you may have to explain a bit more about this process and what it is doing...
perhaps there is a simpler way to do this...


JeffCoachman
0
andrewpiconnectAuthor Commented:
Hi hnasr,

I dont think "Forms("Form1").Undo" will work as Kelvin explained above..<<The moment the focus is moved to another form, form 1's data is written. The undo functionality is then lost.>>"

Jeff,

The process is:
form1 & form2 are question sets split over two forms because there are many questions (approx 100). The idea here was to make the user journey less daunting. Both forms will be linked to a customer on completion of the form2.

The scenario i am trying to avoid here is the inevitable user that will complete half the questions (form1), start on form2 and then decide to abandon the process and click cancel. You know yourself, there is always one user that does the unexpected, so i am merely trying to avoid this scenario.
0
hnasrCommented:
"The moment the focus is moved to another form, form 1's data is written."
Not exactly. This may happen if you tab off last field of form, and force move to next record.

I tried this with form1 modified, then clicked a button to open form2.
Modified form2, clicked a button to undo both forms.

' undo Form2
Me.Undo
'undo Form1
Forms("Form1").Undo

It does what is intended to do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kelvin SparksCommented:
Instead of two forms, use a single tabbed form, where all the data belongs to the one table - just spreads the data over many screens (tabs). The data is not saved until the form is closed.

You can group the data onto tabs according to the logical nature of the data. The many tabs are considered one form - unless you choose to use a subform - in which case the moment you move to that subform, the main form's records are written.


Kelvin
0
andrewpiconnectAuthor Commented:
Kelvin,

I hadnt considered a tabbed form and yes i would think this is a possible solution for many situations. However, the process i have already built is based upon not being able to progress to form2 unless form1's data is valid and complete. Still, a very good suggestion though.

Hnasr,

I will test your solution as i have disabled tabbing off the form and also used << Application.SetOption "Move After Enter" >>, 0 to stop moving to the next record.

The only way the user can progress to form2 is by clicking the "next" button so in theory your solution should work.
0
Jeffrey CoachmanMIS LiasonCommented:
Based on your explanation, I am with Kelvin
Create a tabbed form

<The process is:
form1 & form2 are question sets split over two forms because there are many questions (approx 100). The idea here was to make the user journey less daunting. Both forms will be linked to a customer on completion of the form2.>
This is still a bit vague, ...can you embellish a bit more...

You can certainly require validation before moving to the next tab, but again, we need to know if there is a better way to do this...
0
andrewpiconnectAuthor Commented:
Looks like it was hnasr solution that won this time as it was most relevant to my problem.
Although Kelvin's suggestion of a tabbed form would work in most casesand is well worth keeping in mind, i needed a solution to undo the changes in form1 from form2 as explained at the outset.

I have awarded the points to hnasr accordingly.

FYI and to expand further:
from1 has to be complete and valid before proceeding to form2. (Form2's data is dependant on form1). Once form2 is complete, the user clicks next and is presented with form3 (Form3 is dependant on the data in form1 & 2) and is merely a summary of form1 and form2). From here the user will be able to amend the details of form1 and form2 but only by clicking "Amend" and starting the process again.

If i were to implement a tabbed form i fear my users would be confused on which tab to click first even though i could put validation in guiding them, it may still seem confusing.

The process i am developing is mirroring a website journey ie. page1(gather details), page2(gather more details) page3(show summary).

Thanks for your input all of you!!
0
hnasrCommented:
Welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.