Return without GoSu (Error 3) (1 Viewer)

Siegfried

Registered User.
Local time
Today, 01:10
Joined
Sep 11, 2014
Messages
105
Hi Everyone,

My first post for 2016. Happy New Year!

I'm getting a return without GoSub (Error 3) the first time I open the main form when I start my dbse. The form shows several labels which give a count result.

Code:
Private Sub Form_Current()
     If Me.NewRecord Then
         Me.Parent!lblEvent.Caption = _
          "Event(s): " & Me.Recordset.RecordCount + 1
     Else
         [COLOR=red]Me.Parent!lblEvent.Caption = _
          "Event(s): " & Me.Recordset.RecordCount
[/COLOR]     End If
End Sub

Debug marks the red section.
However, when I just close te Visual Basic for Applications and try again to open the main from, then it opens and shows calculating on the bottom left side of the window. If I close the form once more and then open it, I get all information including the counts on the form. I'm puzzled, does anyone have an idea how I can fix this?

Thanks.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:10
Joined
Feb 19, 2013
Messages
16,605
since you are referring to me.parent, this implies your code is in a subform. Be aware that subforms are loaded before the main form - so you are getting the error because the parent control has not been activated.

See this link for order of events

https://support.office.com/en-us/ar...ects-E76FBBFE-6180-4A52-8787-CE86553682F9#bm3

Not also that some subform events can be triggered multiple times when a main form is opened - put a debug.print into the subform current event to see the impact
 

Cronk

Registered User.
Local time
Today, 09:10
Joined
Jul 4, 2013
Messages
2,772
And to fix the problem?

Two things occur to me.
(1) On error resume next
This will ignore the parent form not being open, but I avoid this as much as possible in case it masks other issues.
(2) Set the parent form's TimeInterval paramater and put the code in the parent form's OnTimerEvent. Bit more work in coding though.
 

Users who are viewing this thread

Top Bottom