By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,650 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,650 IT Pros & Developers. It's quick & easy.

With Statement

P: n/a
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

Nov 13 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

doodle wrote:
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.

Nov 13 '06 #2

P: n/a
On 13 Nov 2006 11:59:05 -0800, pi********@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.
>
doodle wrote:
>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.
Nov 13 '06 #3

P: n/a
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" <AD******@mazakcorp.comwrote in message
news:11**********************@h54g2000cwb.googlegr oups.com...
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

Nov 14 '06 #4

P: n/a
Tom van Stiphout wrote:
On 13 Nov 2006 11:59:05 -0800, pi********@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
CD********@FortuneJames.com

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

Nov 15 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.