toggle button caption on continuous form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • n8kindt
    New Member
    • Mar 2008
    • 221

    toggle button caption on continuous form

    i have a continuous form that i want a toggle button to display "on" or "off." everything i try changes every single caption on the continuous form--rather than the single row. here's what i have so far:
    Code:
    Private Sub Detail_Paint()
    If OnOff.Value = True Then
    OnOff.Caption = "On"
    Else: OnOff.Caption = "Off"
    End If
    End Sub
    it works, but every time the mouse moves over the button, the button flickers. this is not as clean as i would like it to be but if nothing else comes up, i suppose i can live with it.
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hi, there.

    The problem is that the buttons in different rows are just one single control. You could not change an appearance of the button in <all rows.
    A workaround here may be bound ToggleButton control, which certainly requires additional field in the linked table to be bound to.

    Regards,
    Fish

    Comment

    • n8kindt
      New Member
      • Mar 2008
      • 221

      #3
      Originally posted by FishVal
      Hi, there.

      The problem is that the buttons in different rows are just one single control. You could not change an appearance of the button in <all rows.
      A workaround here may be bound ToggleButton control, which certainly requires additional field in the linked table to be bound to.

      Regards,
      Fish
      i'm sorry, i forgot to mention that it was indeed bound. i think i'm going to have to settle with the "flickering " for now. one small problem with this however, is when i delete a record i get runtime error 2424. "the expression you entered has a field, control, or property name that access cannot find." if i click end twice (since the error pops up twice), it works fine. so how do i bypass this error using the code i already have?

      Comment

      • n8kindt
        New Member
        • Mar 2008
        • 221

        #4
        Code:
        If DataErr = 2424 Then
                Response = acDataErrContinue
        End If
        i've got this much... where do i place the code??

        Comment

        • n8kindt
          New Member
          • Mar 2008
          • 221

          #5
          Originally posted by n8kindt
          Code:
          If DataErr = 2424 Then
                  Response = acDataErrContinue
          End If
          i've got this much... where do i place the code??

          this is my final code. i realize i may not have been clear about my problem up above. the code i am listing below is the only solution i have to the problem of every single caption changing whenever one is changed in a continuous form. everything works great now except for a flicker whenever the mouse is moved over the button.

          Code:
          Private Sub Detail_Paint()
          
          On Error GoTo PROC_ERR
          If Not IsNull(Apply1.Value) Then
              If OnOff.Value = True Then
              OnOff.Caption = "On"
              Me.Dirty = False
              Else: OnOff.Caption = "Off"
              End If
          Else: Exit Sub
          End If
          PROC_ERR:
            On Error Resume Next
          End Sub
          can anyone help with the flicker problem?

          Comment

          • n8kindt
            New Member
            • Mar 2008
            • 221

            #6
            minor correction to the above code:

            Code:
            Private Sub Detail_Paint()
            On Error GoTo PROC_ERR
            If Not IsNull([U]OnOff[/U].Value) Then
            If OnOff.Value = True Then
            OnOff.Caption = "On"
            Me.Dirty = False
            Else: OnOff.Caption = "Off"
            End If
            Else: Exit Sub
            End If
            PROC_ERR:
            On Error Resume Next
            End Sub

            Comment

            • FishVal
              Recognized Expert Specialist
              • Jun 2007
              • 2656

              #7
              Hi, there.

              You use Detail_Paint event which I could not find in Access 2003.
              This makes me think you are using Access 2007.
              If so, then you may take advantage of bound Image control to mimick toggle button.

              In form RowSource:
              [code=sql]
              SELECT ..., iif(OnOff, "X:\...\OnButto nFace.bmp", "X:\...\OffButt onFace.bmp") AS txtPathToButton Face FROM ....[/code]

              Image control is bound to [txtPathToButton Face].

              Image_Click event handler inverts [OnOff].Value.

              Button faces may be grabbed directly from screen. ))

              Unfortunately (or maybe fortunately :)) I have no Access 2007. If you does and want to give it a try, then code debugging is all upon you.

              Regards,
              Fish

              Comment

              • n8kindt
                New Member
                • Mar 2008
                • 221

                #8
                Originally posted by FishVal
                Hi, there.

                You use Detail_Paint event which I could not find in Access 2003.
                This makes me think you are using Access 2007.
                If so, then you may take advantage of bound Image control to mimick toggle button.

                In form RowSource:
                [code=sql]
                SELECT ..., iif(OnOff, "X:\...\OnButto nFace.bmp", "X:\...\OffButt onFace.bmp") AS txtPathToButton Face FROM ....[/code]

                Image control is bound to [txtPathToButton Face].

                Image_Click event handler inverts [OnOff].Value.

                Button faces may be grabbed directly from screen. ))

                Unfortunately (or maybe fortunately :)) I have no Access 2007. If you does and want to give it a try, then code debugging is all upon you.

                Regards,
                Fish
                thanks for your advice. yes, i am running access 2007 so i will give your suggestion a go and post back with my results.

                Comment

                Working...