Search code examples
vbams-access

How do I call multiple forms sequentially?


I have data entry broken down into multiple forms that I would like to call sequentially.

I start the first form, and then with a macro attached to a button, open the next form and close and save the first, continuing on.

Is it possible to create a collection of forms and iterate through them with For Each?

Sub FrmEntry()
    Dim Frms as New Collection
    Frms.Add(Forms![FormName])
End Sub

Debugging at this point causes a Runtime error 2450.


Solution

  • Actually, you don't really need to close the previous form.

    Besides, say you looking at a company record.

    Then you click a button say to create a invoice. Why not just launch the invoice form. Then when the user closes the form, the form below (behind) will now show, and you right back to the company form (ready to create another invoice for that company).

    And say you close the company form, then you right back to the "search for a company" form.

    From a users point of view? They all use browsers, and you can/could EVEN have a back arrow button. To the user, they think "go back one", but what you really are doing is simply closing the form.

    When you close the form, the previous one is now in view.

    While in the "old" days, we were "used" to launching a form, maybe move it around, and then perhaps launch another form, and move it around.

    However this so called "multiple document interface" has quite much gone the way of the do do bird.

    Turns out, Access in 2007 (16 years ago!!!) received a NEW tabbed layout option.

    This was in response to web based software, and now tablets etc. In this new "era of UI" then we don't really think of in terms of a form, but only that we want to go back (or choose a option, to go forward).

    Turns out, you can set Access (in main settings), to use tabs, and then turn off tabs. In effect then, all forms take up the whole screen.

    So, you wind up with this look:

    enter image description here

    Note VERY close how a few time I hit that "back" arrow.

    All I am doing is closing the current form, and then going back to previous form. But, that ONLY requires that I close the current form, and then the previous form that was displayed comes back into view.

    As I noted, this is important, since you would not "only" want to open the previous form, but display the previous data that you were working on.

    As you can see, the above takes little more then JUST me

    Openform --- display a new form on top.

    Docmd.OpenForm "form name"
    

    close current form - returns to previous form.

    docmd.Close acForm, me.Name
    

    I mean, open up QuickBooks, or Sage accounting, or just about ANY windows software these days?

    You see that they adopted this type of UI.

    Or you can use/do this option in ms-access:

    enter image description here

    The above is another common setup. You have a set of buttons on the side (or top), and that's your application navigation.

    This is common in web sites (tabs across the top), or the side.

    You can see a video of that example of mine here:

    https://www.youtube.com/watch?v=AU4mH0jPntI

    Now, to be fair, there ARE a number of popup forms.

    And while that sample was Access "web based", unfortunately that option was removed from Access, but the UI can be identical.

    So, in summary:

    YES, a very good idea to hide the previous form. NO, you don't have to write much code to manage that process if you adopt forms that cover the previous form.

    Or, you can as per that 2nd example, use a new navigation form.

    so, while your ideas are good, I don't think you actually need to, or want to worry about "you" managing this form being opened, since there is a BOATLOAD of issues, and one simple issue is when you want to go back to the previous page (back), then you have to not only re-load that form, but also somehow manage what data was being displayed.

    As the above examples show, you don't have to do this, if you design your software UI "flow" to take advantage of the newer UI options we now have in Access.

    Doing so, will result in a "look and feel" that most software has today, be it web based, or Access desktop based.