VBA MS/ACCESS 2010 ensuring Form Load sequence

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
João serras-pereiraAsked:
Who is Participating?
peter57rConnect With a Mentor Commented:
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.
mbizupConnect With a Mentor Commented:
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...

João serras-pereiraAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.