Calling Event Procedure from a Form Variable

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
 
D

Dirk Goldgar

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()
 
M

Mark A. Sam

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Can't insert record 3
Data entry 3
form variable 2
Unique records 2
Problem setting filter with code - is it a bug? 2
Form Closing on its own 0
Reusable Form & Code 2
Firing Change event from popup form 2

Top