Re: 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



Hi Larry,

On Fri, 8 Aug 2008 23:58:58 -0500, "Larry Serflaten"
<serflaten@xxxxxxxxxxxxxx> wrote:

How about passing the form instead. With access to the
form, you can gain access to its Controls collection, plus
Forms have a 'generic' interface you can use (Form) to
allow you to pass any VB form by reference.

I've tried a couple of approaches, and still not having any success.
First, I've changed the call in my UserControl_Initialize() function
to:

Private Sub UserControl_Initialize()
' *** snipped for brevity ***
Viewer.Setup Me

Then I changed my class method to:

Public Function Setup(ByRef Form As Form) As Boolean
Temp = Form.Controls.Count

That gives me the error: "Private object modules cannot be used in
public object modules as parameters or return types for public
procedures, as public data members, or as fields of public user
defined types." I'm a little stumped because the properties for my
form show "Public: Yes". I tried changing the definition of
UserControl_Initialize() to "Public", but that didn't fly (same
error).

Changing the method definition to:

Public Function Setup(Form As Form) As Boolean

generated the same error.

Next, I tried replacing "As Form" with the actual name of my form
module:

Public Function Setup(Form As nsvShowObject) As Boolean
Temp = Form.Controls.Count

But now the assignment to Temp fails because "Controls" is recognized
as a member of "Form", which suggests that "Controls" must be defined
as a Private member. I'm going to do a little more digging, but I have
a feeling that I can't change the definition of "Controls" to be
public.

Any thoughts, suggestions?

Eric
.



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: ActiveSheet.OLEObjects.Add resets globals to Nothing
    ... Adding worksheet controls appears to re-compile the project once the code ... Even that could destroy globals in the other wb. ... Dim temp As Klass1 ...
    (microsoft.public.excel.programming)
  • RE: copy previous record
    ... and copy from the variables into the controls ... At this point you may want to think about using two temp ... Dim strSearch As String ... Dim ctl As Control ...
    (microsoft.public.access.modulesdaovba)
  • Re: ActiveSheet.OLEObjects.Add resets globals to Nothing
    ... Adding worksheet controls appears to re-compile the project once the code ... Amongst other things global variables are destroyed but can get ... Even that could destroy globals in the other wb. ... Dim temp As Klass1 ...
    (microsoft.public.excel.programming)
  • 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)