Call form's event from different form

T

TJ Dowling

I am trying to call a click event (cmdFilter_Click) in one form (frmMaterial)
from another form (frmSelect). The form (frmSelect) defines a SQL string
that can be used by a Filter button on the main form.

Any ideas?

Thanks,
TJ Dowling
 
J

Jeff Boyce

You've explained "how", as in "how you want to accomplish something" (call
click event in another form)...

If you'll provide a bit more specific information about "why" (as in "what
would having the ability to do this allow you/your users to accomplish"),
folks here may be able to offer more specific suggestions.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
L

louisjohnphillips

You've explained "how", as in "how you want to accomplish something" (call
click event in another form)...

If you'll provide a bit more specific information about "why" (as in "what
would having the ability to do this allow you/your users to accomplish"),
folks here may be able to offer more specific suggestions.

Regards

Jeff Boyce
Microsoft Office/Access MVP








- Show quoted text -

TJ:

I won't ask you why you want to do this. I'll tell you that when I
have needed to share code among forms, I write that code in a
Module.

So Module1 may have a function similar to this in it.

Public Function MakeMySqlString( p1 as string ) as string

Dim s as string

s = "SELECT .... "

MakeMySqlString = s

end function

Back in the individual forms, I code:

Private sub cmdFilter_Click()

Dim param1 as string
Dim sReturn as string

param1 = "x"

sReturn = Module1.MakeMySqlString( param1 )

end sub

I write the same type of function call in the other form.

Private sub cmdSelect_Click()

Dim param1 as string
Dim sReturn as string

param1 = "x"

sReturn = Module1.MakeMySqlString( param1 )

end sub
 
P

Pete D.

Wow! Another informitive response from someone that appears to be angry.
Jeff, where have your gone? Can we have the old Jeff back? Please slam me,
you need to get it out of your system! Pete
 
J

Jeff Boyce

Actually, I'm feeling pretty relaxed this afternoon.

I'll have to work on my terminology ... I genuinely was interested in
understanding why the OP wanted to call a click event in a form that didn't
have the focus. In my experience (yes, limited), I don't want forms I can't
see doing things I can't see.

Regards

Jeff
 
M

Michael Gramelspacher

Public sub frmMaterialcmdFilter_Click
call cmdFilter_Click
end sub

You then
call frmMaterialcmdFilter_Click
from somewhere in frmSelect' code

This works for me.

Call Form_frmMaterial.cmdFilter_Click

Subprogram still has to be Public.
 
P

Pete D.

Much better, your back. Truly you have taught us much, Thanks! even if you
have such limited experience. ;}
 
T

TJ Dowling

I had tried this code to call the event:

Call Forms.frmMaterial.cmdFilter_Click

but I did not make the event Public. When I made it Public that did the
trick.

Thanks,
TJ Dowling
 
Top