From: Charlie on
Hey, I can do this

Debug.Print Forms(1).Controls("txtBox").MaxLength

but I can't seem to do this

Debug.Print Forms("frmMain").Controls("txtBox").MaxLength

Is there a syntax to access form objects by name rather than by index?

TIA
Charlie
From: Karl E. Peterson on
It happens that Charlie formulated :
> Hey, I can do this
>
> Debug.Print Forms(1).Controls("txtBox").MaxLength
>
> but I can't seem to do this
>
> Debug.Print Forms("frmMain").Controls("txtBox").MaxLength
>
> Is there a syntax to access form objects by name rather than by index?

No, because there can be multiple instances of a form. (And hopefully
none of them are the default!)

--
..NET: It's About Trust! http://vfred.mvps.org
Customer Hatred Knows No Bounds at MSFT
ClassicVB Users Regroup! comp.lang.basic.visual.misc
Free usenet access at http://www.eternal-september.org


From: MikeD on


"Charlie" <Charlie(a)discussions.microsoft.com> wrote in message
news:4CFBD0AA-7C0C-4558-AB04-96822C5C1FB9(a)microsoft.com...
> Hey, I can do this
>
> Debug.Print Forms(1).Controls("txtBox").MaxLength
>
> but I can't seem to do this
>
> Debug.Print Forms("frmMain").Controls("txtBox").MaxLength
>
> Is there a syntax to access form objects by name rather than by index?
>


No, because that would be ambiguous if you've created 2 or more instances of
the form. You need something that uniquely identifies a specific instance.
For example, you might use its hWnd. This works well in conjunction with API
functions/callbacks which provide you an hWnd. You can loop through the
Forms collection looking for that hWnd to get a reference to that instance
of the form. Another method would be to maintain your own system of a unique
identifier and assign that to the Tag property, and then do the Form loop
thing again to get a reference (but you'd obviously check the Tag property
rather than the hWnd property).

--
Mike


From: Charlie on
Thanks to both of you. I hadn't thought of that. I haven't had the
opportunity to make use of additional instances of forms. Something to think
about.

"MikeD" wrote:

>
>
> "Charlie" <Charlie(a)discussions.microsoft.com> wrote in message
> news:4CFBD0AA-7C0C-4558-AB04-96822C5C1FB9(a)microsoft.com...
> > Hey, I can do this
> >
> > Debug.Print Forms(1).Controls("txtBox").MaxLength
> >
> > but I can't seem to do this
> >
> > Debug.Print Forms("frmMain").Controls("txtBox").MaxLength
> >
> > Is there a syntax to access form objects by name rather than by index?
> >
>
>
> No, because that would be ambiguous if you've created 2 or more instances of
> the form. You need something that uniquely identifies a specific instance.
> For example, you might use its hWnd. This works well in conjunction with API
> functions/callbacks which provide you an hWnd. You can loop through the
> Forms collection looking for that hWnd to get a reference to that instance
> of the form. Another method would be to maintain your own system of a unique
> identifier and assign that to the Tag property, and then do the Form loop
> thing again to get a reference (but you'd obviously check the Tag property
> rather than the hWnd property).
>
> --
> Mike
>
>
> .
>
From: Jeff Johnson on
"Karl E. Peterson" <karl(a)exmvps.org> wrote in message
news:hv6ajk$9fq$1(a)news.eternal-september.org...

>> Hey, I can do this
>>
>> Debug.Print Forms(1).Controls("txtBox").MaxLength
>>
>> but I can't seem to do this
>>
>> Debug.Print Forms("frmMain").Controls("txtBox").MaxLength
>>
>> Is there a syntax to access form objects by name rather than by index?
>
> No, because there can be multiple instances of a form. (And hopefully
> none of them are the default!)

Feh. If there's only going to be once instance of a form I ALWAYS use the
default. (Well, unless it's a dialog box. Then I create a variable.)


 |  Next  |  Last
Pages: 1 2
Prev: INSTR search problem
Next: Pictures