Calling AfterUpdate Event on Separate Form

B

bhikku

I want to trigger the AfterUpdate event on a combo box on one form from the
AfterUpdate event on another form.

Here is the sequence:
- FormA opens
- FormB opens
- A value is selected from a combo box in FormB
- The source table for FormA is updated by the combo box in FormB
- The AfterUpdate event in a combo box in FormA is triggered, which updates
all of FormA
- FormB closes

I have this code in the AfterUpdate event for the combo box in FormB:

Forms.FormA.SetFocus
Forms.FormA.cmbSelectList_AfterUpdate
Forms.FormB.SetFocus
DoCmd.Close

The second line generates the error "Application-defined or object-defined
error".

How do I call an event on an object in a separate form?

b
 
M

microb0x

You are not going to be able to call the AfterUpdate event like that.
It is an event that occurs after an object is updated and is not
something you can call.

Why not just include the code you want to run in the AfterUpdate event
of the combo box in FormB? Or just create a public function that you
can call in both AfterUpdate events.
 
D

Douglas J Steele

Sorry, but that's not correct. The code is simply VBA code that gets called
by an event. You can call the code the same as you can any other VBA.

Two things.

Procedures associated with events are always written as Private Sub
control_event(), such as Private Sub cmbSelectList_AfterUpdate(). In order
to be able to call the code from outside of the form, you need to change
that declaraton to Public Sub cmbSelectList_AfterUpdate()

To call it, you need to use:

Call Form _FormA.cmbSelectList_AfterUpdate
 
W

Wolfgang Kais

Hello "bhikku".

bhikku said:
I want to trigger the AfterUpdate event on a combo box on one form
from the AfterUpdate event on another form.

Here is the sequence:
- FormA opens
- FormB opens
- A value is selected from a combo box in FormB
- The source table for FormA is updated by the combo box in FormB
- The AfterUpdate event in a combo box in FormA is triggered, which
updates all of FormA
- FormB closes

I have this code in the AfterUpdate event for the combo box in FormB:

Forms.FormA.SetFocus
Forms.FormA.cmbSelectList_AfterUpdate
Forms.FormB.SetFocus
DoCmd.Close

The second line generates the error "Application-defined or
object-defined error".

How do I call an event on an object in a separate form?

Try the following:
Create a public sub DoWhatever in the module of FormA and move
the code of the cmbSelectList_AfterUpdate procedure there. Call this
new sub from the cmbSelectList_AfterUpdate procedure. In FormB,
execute the following code in the AfterUpdate event of the combobox:

Forms![FormA].DoWhatever
DoCmd.Close acForm, Me.Name
 
W

Wolfgang Kais

Hello "bhikku".

bhikku said:
I want to trigger the AfterUpdate event on a combo box on one form
from the AfterUpdate event on another form.

Here is the sequence:
- FormA opens
- FormB opens
- A value is selected from a combo box in FormB
- The source table for FormA is updated by the combo box in FormB
- The AfterUpdate event in a combo box in FormA is triggered, which
updates all of FormA
- FormB closes

I have this code in the AfterUpdate event for the combo box in FormB:

Forms.FormA.SetFocus
Forms.FormA.cmbSelectList_AfterUpdate
Forms.FormB.SetFocus
DoCmd.Close

The second line generates the error "Application-defined or
object-defined error".

How do I call an event on an object in a separate form?

Try the following:
Create a public sub DoWhatever in the module of FormA and move
the code of the cmbSelectList_AfterUpdate procedure there. Call this
new sub from the cmbSelectList_AfterUpdate procedure. In FormB,
execute the following code in the AfterUpdate event of the combobox:

Forms![FormA].DoWhatever
DoCmd.Close acForm, Me.Name
 
M

microb0x

I apologize, I was unaware you could change an event procedure for a
form to Public.
 

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

Top