Calling Event Procedure from a Form Variable

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

I would like to call an event procedure from a form variable. Can it be
done? I tried this, and got a message:

Runtime error '2465':
Application-Defined or Object-Defined error.


DoCmd.OpenForm "Order Entry Header Admin", , , "[OrdID] =" & [ordID]

Dim frm As Form
Set frm = Forms("Order Entry Header Admin")
Call frm.Copy_Record_Click

Set frm = Nothing

Can this be done or is my method just wrong.

Thank you for your help and God Bless,

Mark A. Sam
 
Mark A. Sam said:
Hello,

I would like to call an event procedure from a form variable. Can it be
done? I tried this, and got a message:

Runtime error '2465':
Application-Defined or Object-Defined error.


DoCmd.OpenForm "Order Entry Header Admin", , , "[OrdID] =" & [ordID]

Dim frm As Form
Set frm = Forms("Order Entry Header Admin")
Call frm.Copy_Record_Click

Set frm = Nothing

Can this be done or is my method just wrong.


You can do it, but the procedure you call must be Public, not Private.
Since event procedures are Private by default (e.g., "Private Sub
Copy_Record_Click()"), you must modify the event procedure's code to make it
Public:

Public Sub Copy_Record_Click()
 
Thank you Dirk.


Dirk Goldgar said:
Mark A. Sam said:
Hello,

I would like to call an event procedure from a form variable. Can it be
done? I tried this, and got a message:

Runtime error '2465':
Application-Defined or Object-Defined error.


DoCmd.OpenForm "Order Entry Header Admin", , , "[OrdID] =" & [ordID]

Dim frm As Form
Set frm = Forms("Order Entry Header Admin")
Call frm.Copy_Record_Click

Set frm = Nothing

Can this be done or is my method just wrong.


You can do it, but the procedure you call must be Public, not Private.
Since event procedures are Private by default (e.g., "Private Sub
Copy_Record_Click()"), you must modify the event procedure's code to make
it Public:

Public Sub Copy_Record_Click()


--
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)
 
Back
Top