• controls on a form ? (Access 2000)

    Author
    Topic
    #391242

    This is part of a code on a form I use to change the color of the field base on whether the record is new or not. I want to change other fields on the form the same way. Do I have to list each field like I did the [To] field or is the a way to tell the form if this is a new record make all controls or text boxes on the form a certain color? Just looking for a shortcut. Thanks..
    If Me.NewRecord Then
    [To].BackColor = 16777215
    Else
    [To].BackColor = 9868950

    Viewing 1 reply thread
    Author
    Replies
    • #698070

      Something like this:

      Dim lngBackColor As Long
      Dim ctl As Control

      If Me.NewRecord Then
      lngBackColor = 16777215
      Else
      lngBackColor = 9868950
      End If

      For Each ctl In Me.Controls
      ‘ Optional – text boxes only
      If ctl.ControlType = acTextBox Then
      ctl.BackColor = lngBackColor
      End If
      Next ctl

      Set ctl = Nothing

    • #698072

      We’re all looking for shortcuts… smile and so we should…

      You can loop through the Controls collection… Here’s an example procedure from Access 97 Help… You’ll have to adapt it to meet your needs, but I think it demonstrates quite clearly what you are looking to do…

      Sub SetTextBoxProperties(frm As Form)
      Dim ctl As Control

      ‘ Enumerate Controls collection.
      For Each ctl In frm.Controls
      ‘ Check to see if control is text box.
      If ctl.ControlType = acTextBox Then
      ‘ Set control properties.
      With ctl
      .SetFocus
      .Enabled = True
      .Height = 400
      .SpecialEffect = 0
      End With
      End If
      Next ctl
      End Sub

      HTH

    Viewing 1 reply thread
    Reply To: controls on a form ? (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: