• Form_Current Executes twice consecutively (Access 2002, SP3)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Form_Current Executes twice consecutively (Access 2002, SP3)

    Author
    Topic
    #411775

    I have an Access front-end linked to an Access back-end. The FE contains (for our purposes), a login form, a main menu screen, and a Data Entry form which appear in that order when the database is opened. ie. The user opens the db, sees the login form and logs in. Then sees the main form. Clicks a button and sees the Data Entry form. The very weird issue that I’m having is that when I step through the DE form opening procedures, Form_Current runs twice or three times consecutively for the Data Entry form and for the 2 or 3 subforms that are embedded within it. Has anyone ever experienced this? It’s not actually causing problems, but I can’t imagine that it doesn’t hurt my performance. Why should all that code execute more than once? I really can’t see what’s causing it.

    Viewing 0 reply threads
    Author
    Replies
    • #895178

      That’s a very common situation – and it’s never been clear to me why it happens – so we tend to avoid using the Form_Current event unless we absolutely have to. Perhaps someone else has explored this in more detail – I’d love to know the answer.

      • #895193

        Thanks for your response, Wendell. Unfortunately, phasing out the Form_Current event on this form is difficult to do. However, I just did something that seemed to help. In my Form_Open procedure I was setting a filter on the form’s recordset based on a variable that was set when the user logged in. I noticed that the consecutive executions of Form_current were being called when the filter property was changed in Form_Open. I wrote a function to retrieve the value of the variable and created a query which filtered the table by calling the function i.e. the criteria on the ID field is: ALIKE GetLocation & “%”. I removed the code in the Form_Open procedure that set the filter and now it seems to only execute Form_Current once!

        • #895375

          If you have subforms, you’ll also trigger *their* Current event repeatedly. In fact, the current event normally fires multiple times when the form is loading, which is why it’s always desireable to use a flag or some kind of test of Me.Visible = True in the OnCurrent event before executing anything.

          • #895506

            Charlotte, I’m sorry for being thick but let me check if I understood. The form_current event fires multiple times while the form is loading. If I put a condition before my code that checks to see if the form is visible, the code will only execute during the last execution of the form_current event?

            • #895519

              No, it will only execute when the form is visible, which happens after it loads and also happens every time you move to between records.

            • #895525

              Thanks Charlotte – that’s actually what I meant when I said “last execution” – the last of the series that occurs when the form loads up until the point that it’s visible to the user. It sounds like the me.visible check is the way for me to go, then!

            • #895526

              Thanks Charlotte – that’s actually what I meant when I said “last execution” – the last of the series that occurs when the form loads up until the point that it’s visible to the user. It sounds like the me.visible check is the way for me to go, then!

            • #895520

              No, it will only execute when the form is visible, which happens after it loads and also happens every time you move to between records.

          • #895507

            Charlotte, I’m sorry for being thick but let me check if I understood. The form_current event fires multiple times while the form is loading. If I put a condition before my code that checks to see if the form is visible, the code will only execute during the last execution of the form_current event?

        • #895376

          If you have subforms, you’ll also trigger *their* Current event repeatedly. In fact, the current event normally fires multiple times when the form is loading, which is why it’s always desireable to use a flag or some kind of test of Me.Visible = True in the OnCurrent event before executing anything.

      • #895194

        Thanks for your response, Wendell. Unfortunately, phasing out the Form_Current event on this form is difficult to do. However, I just did something that seemed to help. In my Form_Open procedure I was setting a filter on the form’s recordset based on a variable that was set when the user logged in. I noticed that the consecutive executions of Form_current were being called when the filter property was changed in Form_Open. I wrote a function to retrieve the value of the variable and created a query which filtered the table by calling the function i.e. the criteria on the ID field is: ALIKE GetLocation & “%”. I removed the code in the Form_Open procedure that set the filter and now it seems to only execute Form_Current once!

    Viewing 0 reply threads
    Reply To: Form_Current Executes twice consecutively (Access 2002, SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: