RE: Code Help

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Bob Rapp (anonymous_at_discussions.microsoft.com)
Date: 05/13/04


Date: Thu, 13 May 2004 11:41:06 -0700


     This should save you some time. Paste this sub in your code and change the form name. Note: This will change all checkboxes on your form. If there's any checkboxes you don't want changed you can flag them in the Tag event and check the value of ctl.tag in your loop.

Sub ChangeCheckboxes()
    
    Dim ctl As Control
    Dim frm As Form
    Set frm = Forms!YourFormName
    For Each ctl In frm.Controls
        Select Case ctl.ControlType
            Case acCheckBox
                if ctl.Value = True then
                   ctl.BackColor = vbRed
                else
                   ctl.BackColor = vbWhite
               end if
        End Select
    Next
    Set frm = Nothing
End Sub

     ----- Froto wrote: -----
     
     I'm created a calandar in Microsoft access, and have a
     checkbox in each sqaure that if selected it changes the
     background color to red and if unselected it changes back
     to white. Here is the code thats in the on current event
     of the form.
     
     Private Sub Form_Current()
     If Me!Check1.Value = True Then
     Me!ID1.BackColor = vbRed
     Else
     Me!ID1.BackColor = vbWhite
     End If
     End Sub
     
      What I need is how to change the code so that it changes
     the color for every box selected, the code above only
     does 1 box, so if user selects box 1 and box 6 and box 10
     it would only change the background for those boxes, I
     have 31 boxes each with a checkbox.
     
     Thanks for all the help
     



Relevant Pages

  • Re: check boxes
    ... Set frm = Nothing ... Private Sub CommandButton1_Click ... Greg Maxey/Word MVP ... So in my form I have 25 check boxes. ...
    (microsoft.public.word.vba.general)
  • RE: Hiding all combo boxes
    ... Sub Hide_The_Boxes ... Dim ctl As Control ... This will get you started, If you want to pass it specific control names, ... > all the combo boxes to be hidden both on form load and also when changing ...
    (microsoft.public.access.forms)
  • Re: docmd.close makes msaccess crash...
    ... The sub is thus used in a peace of code as following: ... Dim i As Integer ... Dim ctltabset As Control, ctlpage As Control, ctlSub As Control, ... Set frm = Forms ...
    (microsoft.public.access.modulesdaovba)
  • RE: Code For Required Fields
    ... > the error message and exit the subroutine. ... Private Sub Form_BeforeUpdate ... > Private Sub Form_BeforeUpdateDim ctl As Control For Each ...
    (microsoft.public.access.formscoding)
  • Re: determining whether a form is read only
    ... Private Sub cmdShowDetails_Click ... On Error GoTo ErrorPoint ... Set frm = Forms!frmDetails ... Resume ExitPoint ...
    (microsoft.public.access.forms)