Connecting Tech Pros Worldwide Forums | Help | Site Map

With Statement

doodle
Guest
 
Posts: n/a
#1: Nov 13 '06
access 97

can someone tell me the syntax for a with stement for multiple
controls?

pseudo (doesn't work)

With cmbBox1,cmbBox2,cmbBox3
.Visible = False
End With

-doodle


pietlinden@hotmail.com
Guest
 
Posts: n/a
#2: Nov 13 '06

re: With Statement



doodle wrote:
Quote:
access 97
>
can someone tell me the syntax for a with stement for multiple
controls?
>
pseudo (doesn't work)
>
With cmbBox1,cmbBox2,cmbBox3
.Visible = False
End With
>
-doodle
AFAIK, you can't do that. You can create a subroutine in your form
that accepts a control/control name and then you can process them all
individually.

If all you're doing is setting items to visible, then just use
me.cmbBox1.visible=False

or you could use a boolean expression instead of just True or False.

Tom van Stiphout
Guest
 
Posts: n/a
#3: Nov 13 '06

re: With Statement


On 13 Nov 2006 11:59:05 -0800, pietlinden@hotmail.com wrote:

Perhaps you could write:
dim varControls as Variant = Array("cmbBox1","cmbBox2","cmbBox3")
dim varControl as Variant
for each varControl in varControls
Me.Controls(varControl).Visible = False
next varControl

or if you KNOW the controls are numbered successively:
dim i as Integer
for i = 1 to 3
Me.Controls("cmbBox" & i).Visible = False
next i

There is also an interesting way to do it with additional parameters
passed to a function. I'll leave it up to you to read up on
ParamArray.

-Tom.
Quote:
>
>doodle wrote:
Quote:
>access 97
>>
>can someone tell me the syntax for a with stement for multiple
>controls?
>>
>pseudo (doesn't work)
>>
>With cmbBox1,cmbBox2,cmbBox3
> .Visible = False
>End With
>>
>-doodle
>
>AFAIK, you can't do that. You can create a subroutine in your form
>that accepts a control/control name and then you can process them all
>individually.
>
>If all you're doing is setting items to visible, then just use
>me.cmbBox1.visible=False
>
>or you could use a boolean expression instead of just True or False.
Terry Kreft
Guest
 
Posts: n/a
#4: Nov 14 '06

re: With Statement


You don't appear to understand what the With statement is doing for you.

It provides a pointer to an object and cut down the overhead needed to
search for that object in all the objects you could be referring to.

So for your example you should be doing something like:-

With Me
With .cmbBox1
.Visible = False
End With

With .cmbBox2
.Visible = False
End With

With .cmbBox3
.Visible = False
End With
End With


--

Terry Kreft


"doodle" <ADraughn@mazakcorp.comwrote in message
news:1163447268.240473.284990@h54g2000cwb.googlegr oups.com...
Quote:
access 97
>
can someone tell me the syntax for a with stement for multiple
controls?
>
pseudo (doesn't work)
>
With cmbBox1,cmbBox2,cmbBox3
.Visible = False
End With
>
-doodle
>

CDMAPoster@FortuneJames.com
Guest
 
Posts: n/a
#5: Nov 15 '06

re: With Statement


Tom van Stiphout wrote:
Quote:
On 13 Nov 2006 11:59:05 -0800, pietlinden@hotmail.com wrote:
>
Perhaps you could write:
dim varControls as Variant = Array("cmbBox1","cmbBox2","cmbBox3")
dim varControl as Variant
for each varControl in varControls
Me.Controls(varControl).Visible = False
next varControl
>
or if you KNOW the controls are numbered successively:
dim i as Integer
for i = 1 to 3
Me.Controls("cmbBox" & i).Visible = False
next i
>
There is also an interesting way to do it with additional parameters
passed to a function. I'll leave it up to you to read up on
ParamArray.
>
-Tom.
I like Tom's ideas. Here's a way to set the Visible property of all
comboboxes on an A97 form to False:

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then
With Controls(ctl.Name)
.Visible = False
End With
End If
Next ctl

You can set the Tag property to a value and use that to control which
comboboxes disappear:

Dim ctl As Control

For Each ctl In Me.Controls
If ctl.ControlType = acComboBox Then
Select Case Me.Controls(ctl.Name).Tag
Case "HideMe":
With Controls(ctl.Name)
.Visible = False
End With
End Select
End If
Next ctl

Try not to double up on the Tag property. You won't like where that
road leads. Ditto for OpenArgs.

Dim ctl As Control

For Each ctl In Me.Controls
If Right(ctl.Name, 9) = "Ephemeral" Then
If ctl.ControlType = acComboBox Then
With Controls(ctl.Name)
.Visible = False
End With
End If
End If
Next ctl

sets the Visible property of comboboxes with a name ending in Ephemeral
to False.

It's also possible to use other combobox properties such as ForeColor,
which can have values that are just about indistinguishable from each
other. Each shade variation can identify a group of controls. Groups
of control groups can use a color difference metric, say R,G and B
being within one unit of a particular color. I hope this helps.

James A. Fortune
CDMAPoster@FortuneJames.com

A proverb is no proverb to you till life has illustrated it. -- John
Keats

Closed Thread