Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass form or control object to subroutine. 3

Status
Not open for further replies.

fordboy0

Programmer
Jan 24, 2003
13
US
I have searched both high AND low and haven't found the solution for this... Maybe I'm just looking too hard.

I have an application which uses a specific ActiveX control (LEADtools) on many of the forms. With each form, the user will have the opportunity to do the same sorts of things with the control (zoom, crop - whatnot).

It seems to me that if I write a Sub, Function or Class that I can use throughout my app, it would be much easier on me when I need to update some code. Herein lies my problem:

How do I pass the control / form to a sub/func/class so that I can act on it? The following code doesn't work (of course)

Public Sub Zoomin(Leadcontrol as LEAD, ActiveForm as Form)
Forms!ActiveForm.Leadcontrol.Zoomlevel(1)
' More Code Here
End Sub

I don't even get into the sub of course, because of the type-mismatches.

Am I barking up the wrong tree? Suggestions would be fantastic!

Thanks in advance...

-Jeff
 
i think it should be
Public Sub Zoomin(Leadcontrol as control, ActiveForm as object)
Forms!ActiveForm.Leadcontrol.Zoomlevel(1)
' More Code Here
End Sub
 
Oky... Much MUCH closer than before. The passing of the LEAD control works fine, but I'm still having issues with the form.

First off, Thank you to pwise!

Assuming my control name is "LEAD1" and my form name is "orderform" AND I'm using the snippet of code from pwise above (can't thank you enough)

If I call the sub as such:

Zoomin(LEAD1,orderform) <- I get a &quot;ByRef argument type mismatch&quot;

or if I call it like:

Zoomin(LEAD1,Forms![orderform]) or Zoomin(LEAD1,Forms!orderform) <- I get &quot;Can't find the form &quot;ActiveForm&quot; in the Sub line &quot;Forms!ActiveForm.Leadcontrol.Zoomlevel(1)&quot;

Any suggestions? Like I said, the LEAD object is completely usable, but I also have a need for the form as well.

Thanks in advance.

-Jeff
 
i'd try this

Public Sub Zoomin(Leadcontrol as string, ActiveForm as string)
Forms(activeform).form.controls(leadcontrol).Zoomlevel(1)
' More Code Here
End Sub
Christiaan Baes
Belgium
&quot;What a wonderfull world&quot; - Louis armstrong
 
oh yes and just pass strings just in case you did not notice
so just pass the name of the control and the form

Christiaan Baes
Belgium
&quot;What a wonderfull world&quot; - Louis armstrong
 
Thank you all! I ended up using a combination of both of your suggestions. Peace!

-Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top