[AccessD] OT - Looping Through Controls on Visual Basic Form

paul.hartland at fsmail.net paul.hartland at fsmail.net
Wed Jun 8 10:06:14 CDT 2005


Thanks but have already had one, I ended up using the For Each as you suggested...

Thanks for the help anyway...

Paul Hartland





Message date : Jun 08 2005, 04:02 PM
>From : "Josh McFarlane" 
To : "Access Developers discussion and problem solving" 
Copy to : 
Subject : Re: [AccessD] OT - Looping Through Controls on Visual Basic Form
On 6/8/05, paul.hartland at fsmail.net wrote:
> To all,
> 
> I have a lot of text boxes, combo boxes and check boxes on a form and need them locked for certain users I tried the following code to loop through them and when txt, pv or chk is found to lock or disable the control but it doesn't work....
> 
> Dim intFields As Integer
> For intFields = 0 To frmClient.Controls.Count
> If (Left(frmClient.Controls(intFields).Name, 3) = "chk" Or Left(frmClient.Controls(intFields).Name, 3) = "txt") Then
> frmClient(frmClient.Controls(intFields).Name).Locked = True
> End If
> If (Left(frmClient.Controls(intFields).Name, 2) = "PV") Then
> frmClient(frmClient.Controls(intFields).Name).Enabled = False
> End If
> Next intFields
> 
> can anyone tell me what I am doing wrong cause I can't seem to see the wood for the tree's at the moment...
> 
> Thanks in advance for all your help...
> 
> Paul Hartland
Sorry I'm getting into this a little late.

I think you might want to take a look into the tag property for
controls. You label controls with any tags (or a number of tags) and
then search for controls based on that tag, and disable / enable
accordingly.

This really comes in handy when different sets of controls need to be
enabled / disabled for different states. Basic structure is a For Each
statement. If you're interested I can give you a code sample.

-- 
Josh McFarlane

"Peace cannot be kept by force. It can only be achieved by understanding."
-Albert Einstein
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

-- 

Whatever you Wanadoo:
http://www.wanadoo.co.uk/time/

This email has been checked for most known viruses - find out more at: http://www.wanadoo.co.uk/help/id/7098.htm


More information about the AccessD mailing list