VBA MS/ACCESS 2010 ensuring Form Load sequence

Posted on 2012-09-08
Last Modified: 2012-09-09
I have a somwhat complex interface using a Tabbed control and, within the pages, some subforms,
One of the subforms is hidden and holds specific user information on a multi user setup.

I am not getting it to work because I am not able to make sure that this form (F91) is loaded before some of the others. Actually, on the main tab code, on the first Form that I am opening,, the first thing I am doing is to issue a DoCmd to Open the form.

So I think that I should arrange a manner of guaranteeing that F91 is preloaded and should have a test to check if a form is already loaded or not in order to avoid sistematic crashes

how do I do it?

Code snippet:

Private Sub Form_Load()

    Dim IBool As Boolean

 <'---------- CRASH even before this point as some of the other forms and code refers to F91 which Opened after

    Me.F00_UserName = Null
    Me.F00_UserName.Locked = True
    Me.F00_UserPassword = Null
    Me.F00_UserPassword.Locked = True
    DoCmd.OpenForm "F91_LoggedUser", , , , , acHidden
    IBool = InsertLog("CDI Start", "F00 Load", "", "", "", 0, 0, "##NA##", "")
    Forms![F91_LoggedUser]![F0001_Field] = "F0001_DiasFaltam"  
    Forms![F91_LoggedUser]![F0001_FieldState] = "UP"           ' todos os outros campos serão nulos
End Sub
Question by:jirdeaid
    LVL 61

    Assisted Solution

    A couple of things to try:

    - Place the following command immediately after opening F91:

    - You can use the following check anywhere in your database to make sure that F91 is loaded before doing other things:

    If CurrentProject.AllForms("F91").IsLoaded = True Then
        ' Do whatever needs to be done based on F91
        MsgBox "F91 is not loaded"
    End if

    -  If you have information that needs to be readily available around your database, you can also store it in a table, use global variables, use TempVars (for Access 2007 and higher) etc...

    LVL 77

    Accepted Solution

    I'm not clear about what you are saying.

    Is Form F91 the main form or is it a subform?
    If it's a subform then you shouldn't be opening it at all in your code, it will be opened as part of the main form opening process.
    If it's the main form then I don't understand the question at all.

    Author Closing Comment

    I think I shoul either use tempvars or prepare a hidden form llike F91 that is the first form to run.
    I did not know about tempvars before so thanks for the help

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The first two articles in this short series — Using a Criteria Form to Filter Records ( and Building a Custom Filter ( — discuss in some detail how a form can be…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now