How to call a form event from another form

Raneil

Registered User.
Local time
Today, 13:03
Joined
Jun 17, 2005
Messages
10
Hello:

Is it possible to call a form event (actually a control's event within the form) from another form?

Thanks in advance.
 
Yes, but you *must* use Public rather than Private to define the procedure. You can then go through the Forms collection (meaning the form must be loaded) to call the code:
Call Forms!YourFormName!YourControlName.AfterUpdate
 
Help - Calling a form event from another form

I am struggling with the following procedure call:

I have two forms:
1. Cost Model
2. Filter Criteria

I have opened the Filter Critera form from the Cost Model form and defined my search criteria. On closing the Filter Criteria form I want to call the procedure in the Cost Model form - Public Sub ActivateFilter_Click() - to apply the filter criteria to the cost model.

I have tried the format: Forms![Cost Model]!ActivateFilter.Click and several other variants but always get the following error message :

Compile error: Expected: . or (

: refering to the first exclamation mark after Forms.

If I try to use the . I get the following options only: Application, Count, Item, Parent. None of which do what I require. I have had no luck with teh bracket either.

What am I doing wrong?

Any help would be most appreciated

Kevin.
Win 2k with Access 2000
 
Kevin Robson said:
Forms![Cost Model]!ActivateFilter.Click

Try:

Call Forms![Cost Model]!ActivateFilter_Click
 
Last edited:
Thanks for the reply.

I am afraid that the result is exactly the same error message.
 
G’day Kevin.

Please remove spaces from names.

Anyway, as read: -

In Form Cost Model...
Code:
Option Explicit
Option Compare Text


Public Sub ActivateFilter_Click()

    MsgBox "Here in Sub ActivateFilter_Click()"

End Sub


Private Sub cmdTestCallback_Click()

    MsgBox "I will return."
    
    DoCmd.OpenForm "Filter Criteria", acNormal, , , , acDialog, Me.Name
    
    MsgBox "I have returned."

End Sub


In Form Filter Criteria...
Code:
Option Explicit
Option Compare Text


Private Sub Form_Close()

    If Len(Me.OpenArgs) Then
        Forms(Me.OpenArgs).ActivateFilter_Click
    End If

End Sub
However, it’s not going to do anything for you because there is no information flow from Form “Filter Criteria” back to Form “Cost Model”.

But if you get that working at least it’s a start.

Regards,
Chris.
 
Chris,
This works brilliantly, thank you.

Re the passing of data between the forms: I use a public string variable to hold the filter specification as it is used by several procedures. My difficulty was getting the procedures to update automatically in the cost model when I exited the Filter form.

Many Thanks
 

Users who are viewing this thread

Back
Top Bottom