Run-time Error 424 (1 Viewer)

PatAccess

Registered User.
Local time
Today, 06:45
Joined
May 24, 2017
Messages
284
Hello,
I have read a few post of this error but none were helpful to my situation.
This is all I am trying to do. Call the onload function from another form

Private Sub Cmd_OpenFrmNewPEEntry_Click()
Call Frm_NewPEEntry.Form_Load
End Sub

What am I doing wrong?:banghead:
Thank you
 

missinglinq

AWF VIP
Local time
Today, 06:45
Joined
Jun 20, 2003
Messages
6,423
...What am I doing wrong...:banghead:
I would think that the definitive question, here, should be what, exactly, are you trying to accomplish by calling the OnLoad event of another Form!

That aside...to reference anything on a Form...the Form has to be Open and (I believe) Visible.

Linq ;0)>
 

PatAccess

Registered User.
Local time
Today, 06:45
Joined
May 24, 2017
Messages
284
I have this code in this form
Private Sub Form_Load()
If Me.Dirty = True Then Me.Dirty = False
Me.Admin.Value = Forms![Frm_NewPEEntrySearch]!cboAdmin.Column(1)
If Me.PE = True Then
MsgBox "This employee is already marked as PE" & vbNewLine & "Would you like to proceed with adding a new jurisdiction?", vbYesNo
If vbYes Then
DoCmd.OpenForm "Frm_NewPE"
ElseIf vbNo Then
DoCmd.Close
End If
'ElseIf Me.PE = False Then
'DoCmd.Close acForm, "NewPE"
End If
End Sub

and in the other form, I want to call this procedure and I add a code to open the form and close it. It worked at first and then went back to giving me the error 424
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:45
Joined
Feb 19, 2013
Messages
16,553
what is the description for error 424?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:45
Joined
Sep 12, 2006
Messages
15,613
Hi Pat

you ought to put code in
Code:
 tags to make it more readable. I am not sure if this is really carrying out the logic you expect. 


[CODE]Private Sub Form_Load()

    If Me.Dirty = True Then Me.Dirty = False

    Me.Admin.Value = Forms![Frm_NewPEEntrySearch]!cboAdmin.Column(1)

    If Me.PE = True Then
         MsgBox "This employee is already marked as PE" & vbNewLine & "Would you like to proceed with adding a new jurisdiction?", vbYesNo

         If vbYes Then
              DoCmd.OpenForm "Frm_NewPE"  [COLOR="red"]'you maybe ought to open this in dialog form, so you wait until it is closed before continuing. 
[/COLOR]         ElseIf vbNo Then
              DoCmd.Close  [COLOR="Red"]'not sure what this is actually closing![/COLOR]
         End If
         'ElseIf Me.PE = False Then
         'DoCmd.Close acForm, "NewPE"

    End If
End Sub


it's probably docmd.close that requires the object!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:45
Joined
Feb 19, 2013
Messages
16,553
and on what line does the error occur? and how does it relate to the code in your first post?

Also - your second bit of code won't work - check out the code around msgbox.

Finally, please use code tags to preserve indentation - you may know your code but we don't and it is difficult to read without indentation
 

Solo712

Registered User.
Local time
Today, 06:45
Joined
Oct 19, 2012
Messages
828
I would think that the definitive question, here, should be what, exactly, are you trying to accomplish by calling the OnLoad event of another Form!

That aside...to reference anything on a Form...the Form has to be Open and (I believe) Visible.

Linq ;0)>

Right, this is not a good idea. I have never tried it, (nor would I) because "calling" an OnLoad event of another form does not make sense. If the form is already open then re-loading it is redundant, if not then the call would skip the OnOpen event of the form where the form object is set up.

You simply should execute DoCmd.OpenForm and use either a Where condition, or a filter argument or OpenArgs, if there are variants in opening the form.

Best,
Jiri
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:45
Joined
Feb 19, 2013
Messages
16,553
one other general point - your load event (I presume that is the one you are trying to call) is set as private - so cannot be seen outside of the form anyway.
 

Micron

AWF VIP
Local time
Today, 06:45
Joined
Oct 20, 2018
Messages
3,476
In such cases, the code that needs to be run should be in a sub or function in a standard module that you can call from wherever needed. Obviously you'd have to swap out invalid references such as Me .
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 05:45
Joined
Feb 28, 2001
Messages
26,996
I concur with Linq that the form has to be open. I don't think visibility is a factor, but Class modules do not fully honor the PUBLIC attribute of a declaration. It might be called PUBLIC but it is declared PRIVATE at higher scope (the class module itself) so a PUBLIC declaration has no meaning in a Class module. The keyword FRIEND has some effect on visibility of Sub, Function, and Property entry points in Class modules.

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/friend-keyword

My question, though, is why you would write a module to call another form's Load routine? The Load routine has specific context requirements. Are you trying to reset a form to some initial values? If so, you MIGHT do better to write a general module routine to do the INIT based on a specific form, then call it from the form's Load routine by specifying "Me" as the form to be set up. Then you could call it from that OTHER form by naming the form to be initialized via its proper name.
 

Users who are viewing this thread

Top Bottom