Iterating Through Controls on a SalesLogix Form

A common question that I am frequently asked is how to iterate through controls on a SalesLogix form. This is helpful to be able to generically manipulate all, or a set of controls on a form, to do things such as enable/disable controls at runtime etc without the need to specifically hard-code the names of the controls.

Here’s an example. This code iterates through all controls and sets the enabled property to false:

Dim i

    On Error Resume Next

    For i = 0 To ControlCount - 1
        Controls(i).Enabled = False
    Next

Easy enough. The SalesLogix form exposed two properties that make this possible. First the ControlCount property will return the number of controls on the form. The Controls collection contains a reference to each of these controls. Note: SalesLogix collections don’t work well with For Each loops. Stick with a For loop instead and access collection items by index instead.

You can do anything you want with the control reference in the loop. Finding out which type of control you’re working with is easy with the TypeName method. If you pass to it a control reference it will pass back the type of control it is. Here’s an example that sets only checkboxes disabled:

Dim i

    On Error Resume Next

    For i = 0 To ControlCount - 1
        If TypeName(Controls(i)) = "CheckBox" Then Controls(i).Enabled = False
    Next

Access whatever properties you need once you have the control reference. Often it is useful to use the Tag property to flag controls needed for some specific operation. However, be careful to not access a property while iterating through controls that might not exist on all controls (such as the Text property).

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Brad, great use of this.

    I’d tweak that a bit to only display a single msgbox with all required fields listed and it would be a great thing to put into a generic include script. You could even make it so you passed a form reference and then used the Controls collection for that form and displayed the message. Then you’d have a generic script you could just pass the form reference to when the form attempted to close.

    -Ryan

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!