Why doesn't this code work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J Lagos

    Why doesn't this code work?

    The intent is to cycle through text boxes on a reports detail section and
    change the backcolor depending on the text box value.

    the debug.print seems to indicate that the value is coming through, but the
    backcolor isn't changing to correspond.

    here's the code: (if anyone has more brains that me on this..I'm missing
    something here)

    Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
    Dim ctl As Control
    Dim strV

    Const conTransparent = 0
    Const conWhite = 16777215
    Const conRed = 255
    For Each ctl In Me.Controls

    With ctl
    If .ControlType = acTextBox And .Section = acDetail Then
    strV = ctl
    strV = Right(strV, 1)
    .BackStyle = acNormal
    Debug.Print ctl.Name
    Debug.Print strV
    Select Case strV
    Case Is = "R"

    .BackColor = 255

    Case Is = "L"
    .BackColor = 1

    Case Else

    End Select
    End If
    End With

    Next ctl

    End Sub

  • Mark

    #2
    Re: Why doesn't this code work?

    1. You don't need the constants (Const) since you are specifying the
    actual value of backcolor
    2. You don't need the variable strV to do what you want
    3. In your Select Case statement, you are looking at the values (strV)
    your controls might have rather than than the value of the controls

    Steve

    "J Lagos" <rushrules__@sh aw.cawrote in message
    news:%N5ck.6063 4$Jx.18913@pd7u rf1no...
    The intent is to cycle through text boxes on a reports detail section and
    change the backcolor depending on the text box value.
    >
    the debug.print seems to indicate that the value is coming through, but
    the backcolor isn't changing to correspond.
    >
    here's the code: (if anyone has more brains that me on this..I'm missing
    something here)
    >
    Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
    Dim ctl As Control
    Dim strV
    >
    Const conTransparent = 0
    Const conWhite = 16777215
    Const conRed = 255
    For Each ctl In Me.Controls
    >
    With ctl
    If .ControlType = acTextBox And .Section = acDetail Then
    strV = ctl
    strV = Right(strV, 1)
    .BackStyle = acNormal
    Debug.Print ctl.Name
    Debug.Print strV
    Select Case strV
    Case Is = "R"
    >
    .BackColor = 255
    >
    Case Is = "L"
    .BackColor = 1
    >
    Case Else
    >
    End Select
    End If
    End With
    >
    Next ctl
    >
    End Sub

    Comment

    • Stuart McCall

      #3
      Re: Why doesn't this code work?

      "J Lagos" <rushrules__@sh aw.cawrote in message
      news:%N5ck.6063 4$Jx.18913@pd7u rf1no...
      The intent is to cycle through text boxes on a reports detail section and
      change the backcolor depending on the text box value.
      >
      the debug.print seems to indicate that the value is coming through, but
      the backcolor isn't changing to correspond.
      >
      here's the code: (if anyone has more brains that me on this..I'm missing
      something here)
      >
      Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
      Dim ctl As Control
      Dim strV
      >
      Const conTransparent = 0
      Const conWhite = 16777215
      Const conRed = 255
      For Each ctl In Me.Controls
      >
      With ctl
      If .ControlType = acTextBox And .Section = acDetail Then
      strV = ctl
      strV = Right(strV, 1)
      .BackStyle = acNormal
      Debug.Print ctl.Name
      Debug.Print strV
      Select Case strV
      Case Is = "R"
      >
      .BackColor = 255
      >
      Case Is = "L"
      .BackColor = 1
      >
      Case Else
      >
      End Select
      End If
      End With
      >
      Next ctl
      >
      End Sub
      Is your control's BackStyle property set to Normal? If so, set it to
      Transparent.


      Comment

      • StopThisAdvertising

        #4
        Re: Why doesn't this code work?


        "Mark" <emasil@email.o rgschreef in bericht news:uridnXHaV8 pLm-zVnZ2dnUVZ_hCdn Z2d@earthlink.c om...
        1. You don't need the constants (Const) since you are specifying the
        actual value of backcolor
        2. You don't need the variable strV to do what you want
        3. In your Select Case statement, you are looking at the values (strV)
        your controls might have rather than than the value of the controls

        Steve

        --
        Hey Mark/Steve!! We don't need you here !!
        Hey Mark/Steve!! We don't want you here !!

        This is to inform 'newbees' here about PCD' Steve:
        http://home.tiscali.nl/arracom/whoissteve.html (updated, mainly the 'abuse-reporting' page...)
        Until now 5850+ pageloads, 3675+ first-time visitors
        (these figures are real and rapidly increasing)

        Why is this ???
        Because Steve is the ONLY person here who continues to advertise in the groups.

        It is not relevant whether he advertised in *this* particular post or not...
        ==We want him to know that these groups are *not* his private hunting grounds!

        For those who don't like too see all these messages:
        ==Simply killfile 'StopThisAdvert ising'.
        Newbees will still see this warning-message.

        ArnoR

        Comment

        • Stuart McCall

          #5
          Re: Why doesn't this code work?

          Errata:
          Is your control's BackStyle property set to Normal? If so, set it to
          Transparent.
          should have been:

          Is your control's BackStyle property set to Transparent? If so, set it to
          Normal.

          Duh.


          Comment

          • Arno R

            #6
            Re: Why doesn't this code work?


            "J Lagos" <rushrules__@sh aw.caschreef in bericht news:%N5ck.6063 4$Jx.18913@pd7u rf1no...
            The intent is to cycle through text boxes on a reports detail section and
            change the backcolor depending on the text box value.

            the debug.print seems to indicate that the value is coming through, but the
            backcolor isn't changing to correspond.

            here's the code: (if anyone has more brains that me on this..I'm missing
            something here)

            Private Sub Detail_Format(C ancel As Integer, FormatCount As Integer)
            Dim ctl As Control
            Dim strV

            Const conTransparent = 0
            Const conWhite = 16777215
            Const conRed = 255
            For Each ctl In Me.Controls

            With ctl
            If .ControlType = acTextBox And .Section = acDetail Then
            strV = ctl
            strV = Right(strV, 1)
            .BackStyle = acNormal
            Debug.Print ctl.Name
            Debug.Print strV
            Select Case strV
            Case Is = "R"

            .BackColor = 255

            Case Is = "L"
            .BackColor = 1

            Case Else

            End Select
            End If
            End With

            Next ctl

            End Sub
            >
            The line
            .BackStyle = acNormal
            should be
            .BackStyle = 1

            Furthermore you need to specify a value for the Case Else situation (you will see...)
            Mark (Steve) is right (for a change) with his comments regarding the constants.

            Arno R

            Comment

            Working...