none
Problem with events when have two forms opended at the same time. RRS feed

  • Question

  • Hi all,

    I have two forms opened in acWindowNormal mode at the same time

    My issue is when  the user clicks on the second form

    the events from the controls in the first form (afterupdate or lost_focus)

    does not fire before the click envents from the second form.

    Make the form modal is not a solution in this case because I need to the user be able to click in one of those two forms at any time.

    The problem is when a user write in a textbox in the first form and then clicks in the second form without press enter or tab  in the textbox (the event doesnt fire). In this case data can be lost.... 

    Is there some way to get around this situation ?

    Thanks.


    Joao Simplicio Rodrigues

    Sunday, July 16, 2017 10:30 PM

Answers

  • That's by design: you did not finish your edit in form1, so it did not get saved when you switched to form2. Oh, the horrors if it would do otherwise.

    However, you are mistaken, no data got lost. Just not saved yet.

    Best thing to do would be reconsider opening both forms at the same time. If form2 depends on form1 having its data saved, then only open form1 and offer a button "Save and Open form2". In the click event you save (and perhaps close) the current form, and open the second.


    -Tom. Microsoft Access MVP

    Monday, July 17, 2017 12:07 AM

All replies

  • That's by design: you did not finish your edit in form1, so it did not get saved when you switched to form2. Oh, the horrors if it would do otherwise.

    However, you are mistaken, no data got lost. Just not saved yet.

    Best thing to do would be reconsider opening both forms at the same time. If form2 depends on form1 having its data saved, then only open form1 and offer a button "Save and Open form2". In the click event you save (and perhaps close) the current form, and open the second.


    -Tom. Microsoft Access MVP

    Monday, July 17, 2017 12:07 AM
  • If you really need to be able to move back and forth between the two forms while editing data try putting the following in the Deactivate event procedure of each form:

        Me.Dirty = False

    This should save any edited data once you move focus to the other form.  However, as with any approach which prematurely saves a record, you might well have to prejudice the integrity of the data by inappropriately allowing Nulls in some columns.

    I'd be interested in knowing what is the rationale behind having two bound forms open simultaneously at the same record.

    Ken Sheridan, Stafford, England

    Monday, July 17, 2017 4:53 PM
  • Are you attempting to allow two users to enter data in the same record at the same time? For example, one user enters data in one field and another user enters data in another field, but both in the same record? Is this correct?

    If so, you could create a temporary table that is a clone of your Record Source in form 1 to temporarily hold data entered in form 2 and then when the record in form 1 is free, you could use an Update query to update the data from the temporary table to the form 1 data table. Then delete all the records in the temporary table and start over again. It's a very clunky risky solution and requires you to really know what you are doing, but could work.

    ACCESS does not allow multiple updates to a record at the same time for a very good reason.


    Monday, July 17, 2017 10:17 PM
  • Hi João Simplicio Rodrigues,

    you had mentioned that,"the events from the controls in the first form (afterupdate or lost_focus).does not fire before the click envents from the second form."

    I try to make a test on my side.

    I use code below to open form.

    Sub deemo()
    DoCmd.OpenForm ("frm_tblboard")
    DoCmd.OpenForm ("frm_tblboardlocation")
    End Sub

    on textbox of first form I create 2 events mentioned by you. below is the result.

    the lost focus event execute immediately when ever it lost the focus from the control.

    after update event is also execute correctly.

    I want to confirm with you that do you get the same output like mine or different?

    the other thing you had mentioned that,"The problem is when a user write in a textbox in the first form and then clicks in the second form without press enter or tab  in the textbox (the event doesnt fire). In this case data can be lost"

    you can see in the video above that data not getting loss. what changes I made in data it stay as it is when I change the form. I did not press enter or tab.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, July 18, 2017 2:02 AM
    Moderator
  • I explained my question wrongly.
    Effectively the events Lost_Focus and After_update of the first form trigger.

    Unfortunately for me it only fires after the click event of the second form.

    And it is in the click event of the second form that I trigger the process of saving the data of the first one.

    This second form only has command buttons and has no data

    It is always open and serves as a kind of television command.

    The forms with data are being opened and closed by the clicks in this second form.

    I was to use the Ribbon but this way it was more pleasant. I wish I could show you ...

    Everything you all wrote here is correct.

    My approach that I made was wrong.

    The solution I implemented was to close the first form before saving the data. This way the data is already saved as I intended.

    I'll consider Tom's answer correct because it was his suggestion (and perhaps close) that got me on the right path.

    Thank you all.


    Joao Simplicio Rodrigues



    Friday, July 21, 2017 7:24 PM