[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


OpenArgs On Form_Load not triggered

Posted on 2004-10-29
Medium Priority
Last Modified: 2008-02-01
I have two forms which I navigate back and forth between then viewing associated records.  I use docmd.openform with the openargs being the ID of the record I want to goto.  In the load event for each form I use this code to get to the record I need:

If Not IsNull(Me.OpenArgs) Then

  Set rs = Me.RecordsetClone
  rs.FindFirst "SDVN_NUM = '" & Me.OpenArgs & "'"
      If Not rs.NoMatch Then
      Me.Bookmark = rs.Bookmark
    End If
End If

This works great the first time, however when both forms are opened the load event is not triggered and it does not perform navigation.  I would like to solve this without having to close the forms in between calls. Just wondering how others handle this type of situation?

Question by:BillPowell
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 58

Expert Comment

ID: 12449421
The event you want is Form_Activate

Create a normal module, say basGlobal, containing:

    Global gstrArgsForFormA As String

Whenever you need the form A, use:

    gstrArgsFormFormA = "cboID;123"   ' or whatever you would feed as OpenArg
    Docmd.OpenForm "FormA"

In Form A, use:

Private Sub Form_Activate()

    If gstrArgsForFormA <> "" Then
        ' use the argument here
        gstrArgsForFormA = ""   ' (reset)
    End If

End Sub

This works, I use it all over the place... :)
LVL 44

Expert Comment

ID: 12449566
if you are not closing and disposing  of the form (Set Form = Nothing) then the form, once loaded, stays in memory, and Form_Load is NOT called again.  The form is displayed (.Visible = True), but NOT re-loaded.  That is why Form_Load is the wrong place.  When .Visible = True occurs, the Form_AcTivate is then called (the form has been 're-activated')

LVL 58

Expert Comment

ID: 12449589
Not quite, AW

Form_Activate is the "On Got Focus" of forms. It has little to do with .Visible (an unvisible form can't get the focus).

Also "set Form = Nothing" has no clear meaning in this context. It's more confusing than helpful, imho.

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Author Comment

ID: 12449885
Good suggestion harfang.  My only workarounds previously was to ensure I closed the calling form so that the onload would get triggered again when I needed that form again.  I have used a modified version of your method in the past, but had always thought of it as less than ideal solution because of having to resort to using a global variable.  Now that I see others use it, I guess it cant be that bad.
LVL 58

Accepted Solution

harfang earned 1600 total points
ID: 12450056
Well, ok, if you want the purist's version...

Declare a public string in FormA, as in:

    Public ActivateArgs as String

Use any of the "FormIsOpen()" functions (there is one in Access Help, btw), and then go...

    If FormIsOpen("FormA") Then
        With Forms!FormA
            !ActivateArgs = "xxxxx"
        End With
        DoCmd.OpenForm "FormA", OpenArgs:="yyyyy"

Now you need to check Me.OpenArgs in Form_Open *and* Me.ActivateArgs in Form_Activate....
It it really better?

Now the really, really, really object oriented approach...
(provided that your form isn't a dialog box, which seems not to be the case)
Create a public *method*!!! In FormA:

Public Sub JumpToRecord(pstrKey)
   ' do your stuff here
End Sub

Then you can...

    DoCmd.OpenForm "FormA"

Well, there you go!
LVL 58

Expert Comment

ID: 12450073
Sorry, in the last line I meant:
   Forms!FormA.JumpToRecord Me.strMyKey
although the bracketed version should have worked in that particular case...
LVL 11

Author Comment

ID: 12450250
Thanks for the extra tidbit.  Im thinking Ill stick to the global variable option.  I might add a custom property to write which form was the calling form.  That way I can opt out of navigating to the record if the form was not called by the last form that modified the global variable.



Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

656 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