PC Review


Reply
Thread Tools Rate Thread

Loop through Report Controls collection

 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      16th Aug 2004
I want to loop through the collection of controls on a report so that I can
set the font size of each depending on the [Pages] count in a Report Header
OnPrint event.

My code below produces "Object doesn't support this method"

Can someone help with proper syntax please?

Thanks.

Alan

Code
------
Private Sub PageHeader0_Print(Cancel As Integer, PrintCount As Integer)
' Reduce font size to 10 from present 11 for all fields if page count >
2

If [Pages] > 2 Then
Dim col As New Collection
Dim ctl As Control

For Each ctl In Me.Controls
Me.Controls(ctl).FontSize = 18
Next
End If
End Sub



 
Reply With Quote
 
 
 
 
Tim Ferguson
Guest
Posts: n/a
 
      16th Aug 2004
"Alan Z. Scharf" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> My code below produces "Object doesn't support this method"


You don't say which line causes the error, so I can only hazard a guess
that it is this one:

> Me.Controls(ctl).FontSize = 18


Not all controls have a .FontSize property. Easiest thing is simply to dump
the error by wrapping it in a On Error Resume Next... On Error Goto 0 pair;
or else you could test explicitly by iterating the ctl.Properties
collection.

Incidentally, I have just noticed that the line as quoted is not even
legal. You can index the .Controls collection using a number or a string
(i.e Me.Controls(12) or Me.Controls("sfrmVisits") ) but ctl is dimmed as a
Control. I assume this is a typo and you meant

ctl.FontSize = 18

HTH


Tim F

 
Reply With Quote
 
 
 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      16th Aug 2004
Tim,

Thanks for your reply.

I got it using:

For Each ctl In Controls
ctlName = ctl.Name
If Me.Controls(ctlName).ControlType = acLabel Or
Me.Controls(ctlName).ControlType = acTextBox Then
Me.Controls(ctlName).FontSize = 10
End If
Next

"Tim Ferguson" <(E-Mail Removed)> wrote in message
news:Xns9547C13F55424garbleme4455656@207.46.248.16...
> "Alan Z. Scharf" <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > My code below produces "Object doesn't support this method"

>
> You don't say which line causes the error, so I can only hazard a guess
> that it is this one:
>
> > Me.Controls(ctl).FontSize = 18

>
> Not all controls have a .FontSize property. Easiest thing is simply to

dump
> the error by wrapping it in a On Error Resume Next... On Error Goto 0

pair;
> or else you could test explicitly by iterating the ctl.Properties
> collection.
>
> Incidentally, I have just noticed that the line as quoted is not even
> legal. You can index the .Controls collection using a number or a string
> (i.e Me.Controls(12) or Me.Controls("sfrmVisits") ) but ctl is dimmed as a
> Control. I assume this is a typo and you meant
>
> ctl.FontSize = 18
>
> HTH
>
>
> Tim F
>



 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      16th Aug 2004
Your code is doing a lot more work than is required:

For Each ctl In Controls
If ctl.ControlType = acLabel Or ctl.ControlType = acTextBox Then
ctl.FontSize = 10
End If
Next


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



"Alan Z. Scharf" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Tim,
>
> Thanks for your reply.
>
> I got it using
>
> For Each ctl In Controls
> ctlName = ctl.Name
> If Me.Controls(ctlName).ControlType = acLabel Or
> Me.Controls(ctlName).ControlType = acTextBox Then
> Me.Controls(ctlName).FontSize = 10
> End If
> Next
>
> "Tim Ferguson" <(E-Mail Removed)> wrote in message
> news:Xns9547C13F55424garbleme4455656@207.46.248.16...
> > "Alan Z. Scharf" <(E-Mail Removed)> wrote in
> > news:(E-Mail Removed):
> >
> > > My code below produces "Object doesn't support this method"

> >
> > You don't say which line causes the error, so I can only hazard a guess
> > that it is this one:
> >
> > > Me.Controls(ctl).FontSize = 18

> >
> > Not all controls have a .FontSize property. Easiest thing is simply to

> dump
> > the error by wrapping it in a On Error Resume Next... On Error Goto 0

> pair;
> > or else you could test explicitly by iterating the ctl.Properties
> > collection.
> >
> > Incidentally, I have just noticed that the line as quoted is not even
> > legal. You can index the .Controls collection using a number or a string
> > (i.e Me.Controls(12) or Me.Controls("sfrmVisits") ) but ctl is dimmed as

a
> > Control. I assume this is a typo and you meant
> >
> > ctl.FontSize = 18
> >
> > HTH
> >
> >
> > Tim F
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
loop through field names, then use to loop through records topopulate grid pmacdiddie@gmail.com Microsoft Access Form Coding 1 4th Jan 2008 02:13 PM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
How to step through the controls in a webform controls collection Dave Adler Microsoft VB .NET 1 18th Feb 2004 12:50 AM
Infinite Loop Infinite Loop Infinite Loop Infinite Loop... Donna Windows XP Setup 0 8th Dec 2003 11:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:14 PM.