Link to home
Start Free TrialLog in
Avatar of andrewpiconnect
andrewpiconnectFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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?
Avatar of Kelvin Sparks
Kelvin Sparks
Flag of New Zealand image

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
Avatar of andrewpiconnect

ASKER

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
' undo Form2
Me.Undo
'undo Form1
Forms("Form1").Undo
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
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.
ASKER CERTIFIED SOLUTION
Avatar of Hamed Nasr
Hamed Nasr
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.
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...
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!!
Welcome!