Passing "Controls" collection to a class method not defined in .ctl file

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I'm trying to pass the "Controls" collection from the
UserControl_Initialize() routine in my .ctl file to a class method
defined in a separate module. Here's the .ctl code:

Private Sub UserControl_Initialize()
m_Viewer = VIEWER_GLOBAL360
Select Case m_Viewer
Case VIEWER_GLOBAL360
Set Viewer = New ViewerG360
Case VIEWER_UNISOFT
Set Viewer = New ViewerUnisoft
End Select
Viewer.Setup Controls

"ViewerG360" and "ViewerUnisoft" are classes (each defined in their
own .cls file) which encapsulate the functionality of a graphics
toolkit. (In the future, I may define more of these classes as I
support more graphics libraries.) The G360 toolkit needs to add
controls to my form; the Unisoft viewer does not. I want to pass the
"Setup" method the forms's "Controls" array so that the toolkit can
add controls if it needs to. (I'm trying to avoid a bunch of in-line
code which tests for different graphics toolkits and performs whatever
logic is required.)

Here's the start of the ViewerG360.Setup method:

Public Function Setup(Controls As ComctlLib.Controls) As Boolean
Dim szWang As String
szWang = GetWangControlString(WANG_EDIT_OCX)
Set wimgView = Controls.Add(szWang, "ctl1")
If wimgView Is Nothing Then
MsgBox "Error during dynamic load of " & szWang
Else
szWang = GetWangControlString(WANG_THUMB_OCX)
Set wimgThumb = Controls.Add(szWang, "ctl2")
If wimgThumb Is Nothing Then
MsgBox "Error during dynamic load of " & szWang
Else

This code sequence gives me a "Run-time error '13': Type mismatch".

I've tried some alternatives, such as:

Public Function Setup(Controls As Controls) As Boolean

but that gives me the same error. I've also tried:

Public Function Setup(xxx) As Boolean
Dim szWang As String
Dim Controls As ComctlLib.Controls
Set Controls = xxx
Setup = False
szWang = GetWangControlString(WANG_EDIT_OCX)
Set wimgView = Controls.Add(szWang, "ctl1")

but that gives "Compile error: Method or data member not found".

I've been Googling for a couple of hours now, but haven't found any
good clues. Am I just barking up the wrong tree, or am I missing
something obvious?

Any help would be graciously appreciated!
Eric

--
Eric Chevalier E-mail: etech@xxxxxxxxxxxxxxxx
Web: www.tulsagrammer.com
Is that call really worth your child's life? HANG UP AND DRIVE!
.



Relevant Pages

  • Re: Set forms properties from a Public Function in a utilities mo
    ... No worries Jim! ... all of the controls in whatever form gets passed are ... available for your coding please in a public function as well. ... Dim sText As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Passing "Controls" collection to a class method not defined in .ctl file
    ... Public Function SetupAs Boolean ... Temp = Form.Controls.Count ... public object modules as parameters or return types for public ... But now the assignment to Temp fails because "Controls" is recognized ...
    (microsoft.public.vb.controls)
  • Re: Read Only Form allow a search
    ... I have over 30 controls on my ... > Public Function fncLockUnlockControls ... > Dim ctl As Control ... > Dirk Goldgar, MS Access MVP ...
    (microsoft.public.access.formscoding)
  • Re: when is the time right to create a sub to do something?
    ... If you use the after update event of the control, ... then if the user hits tab OR the enter key, both keys will work for you. ... highlight twelve controls on the screen all at the same time, ... in the name of the public function you want in each of those twelve controls ...
    (microsoft.public.access.formscoding)
  • Re: How to repeat code that is used in all forms
    ... I think you can do this by creating a Public Function or Sub in a Module. ... controls from a module, which you can use as an example to modify the code ... Dim ctl As Control ...
    (microsoft.public.access.gettingstarted)