Call form's event from different form

  • Thread starter Thread starter TJ Dowling
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
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.
 
Much better, your back. Truly you have taught us much, Thanks! even if you
have such limited experience. ;}
 
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
 

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

Back
Top