Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

With - End With

Status
Not open for further replies.

Binnit

Technical User
Apr 28, 2004
627
US
Please can someone tell me if there is there a way to specifiy multiple controls to apply the same With statement to?

Somthing like:-

With Me.txtfield1; me.txtfield2
.locked=false
.backcolour =
etc
End With




If IT ain’t working Binnit and Reboot
 
Thanks MP9 but our systems lockdown has blocked that link you provided. Any other thoughts?


If IT ain’t working Binnit and Reboot
 
From that site:

Conditional formatting by control type
97 / 2000 / 2002 / 2003
Ever wanted to apply formatting to all the controls of a form at the same time? Easy! All the examples shown are running from the form's Open event, but could just as easily be applied to the Current event if you want different formatting for different records. The first example simply disables all the controls by setting their Enabled properties to False:
Private Sub Form_Open(Cancel As Integer)
'Code sample from Accessory On Error Resume Next 'In case some controls without the relevant property are considered
Dim ctl As Control
For Each ctl In Me.Controls
ctl.Enabled = False
Next ctl
End Sub
This is fine but has an ugly method of handling those controls that don't support the property you want to modify, i.e. it justs skips the error. Wouldn't it be nicer to just reformat relevant controls? The ControlType property lets you do this, as in the following example which disables all controls except Labels:
Private Sub Form_Open(Cancel As Integer)
'Code sample from Accessory Dim ctl As Control
For Each ctl In Me.Controls
'ControlType constants you can use
'acLabel - Label
'acRectangle - Rectangle
'acLine - Line
'acImage - Image
'acCommandButton - Command button
'acOptionButton - Option button
'acCheckBox - Check box
'acOptionGroup - Option group
'acBoundObjectFrame - Bound object frame
'acTextBox - Text box
'acListBox - List box
'acComboBox - Combo box
'acSubform - SubForm / SubReport
'acObjectFrame - Unbound object frame or chart
'acPageBreak - Page break
'acPage - Page
'acCustomControl - ActiveX (custom) control
'acToggleButton - Toggle button
'acTabCtl - Tab
ctl.Enabled = (ctl.ControlType <> acLabel)
Next ctl
End Sub
Which is all well and good except what happens if you want to format an eclectic selection of controls of different types? Well you could use the control's Name property to uniquely identify each one and scroll throught them all but how laborious is that if you have lots of controls to do this for? Plus if you make changes to the form, adding or removing controls, you have to change your code too. I prefer to make use of each control's Tag property, as in the following example which disables all controls with a Tag property of "X":
Private Sub Form_Open(Cancel As Integer)
'Code sample from Accessory Dim ctl As Control
For Each ctl In Me.Controls
ctl.Enabled = (ctl.Tag <> "X")
Next ctl
End Sub
 
Rubbernilly
Thanks for the copy/paste, I am disapointed that there is no simple way of adding multiple control references to a With statement, however thats not your fault!

The problem is I also use the Tag option for checking controls are completed within the beforeupdate event in a similar fashion as described by the brinkster method.

Oh well, I only want to do a few so guess have to carry on and do each one indvidually.
Thanks anyway

If IT ain’t working Binnit and Reboot
 
It is not as clean as what you are looking for, but you could name them as an iteration and then cycle through the set...

For instance, textboxes named:
Text1
Text2
Text3

Code:
Dim a as integer

For a = 1 to 3
  With Me("Text" & a)
    .locked = False
    'etc.
  End With
Next a

This would at least keep the typing to a minimum, and the corrections later could be made in one place rather than several, but it doesn't cut down on the number of lines you have to process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top