Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    controls on a form ? (Access 2000)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: controls on a form ? (Access 2000)

    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

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Toronto, Ontario, Canada
    Posts
    314
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: controls on a form ? (Access 2000)

    We're all looking for shortcuts... <img src=/S/smile.gif border=0 alt=smile width=15 height=15> 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

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Posts
    294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: controls on a form ? (Access 2000)

    Thanks. Works great...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •