Plus & Minus Buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Will James
    New Member
    • Dec 2011
    • 11

    Plus & Minus Buttons

    Is it as easy to implement into my form as I think?

    I have a text field called Qty in a form, and I would like to have a plus (+) and Minus (-) buttons to increase or decrease the number in the text field, is this possible and easy?

    I have found a example online but it doesn't work!

    Could someone be kind enough to help.

    Thank You
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    Perhaps it is not the example that does not work but your implementation of the example. If you share your work with us we could help you with that.

    It will be very simple. Each button will have have one statement in the OnClick event for the button, something like:
    Code:
    me!nameoftextbox = me!nameoftextbox-1
    or +1 instead of -1

    plus you may want to add some error handling.

    Jim

    Comment

    • Will James
      New Member
      • Dec 2011
      • 11

      #3
      Hi there

      This is the code I found:

      Code:
          If KeyCode = 107 Then
              Me.Text1 = Me.Text1 + 1
              KeyCode = 0
          ElseIf KeyCode = 109 Then
              Me.Text1 = Me.Text1 - 1
              KeyCode = 0
      End If
      I changed the text1 to the name on my field
      Last edited by NeoPa; Dec 6 '11, 01:23 AM. Reason: Fixed *s

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        That code doesn't look like it's for buttons Will. If I were a guessing man I'd say that was trying to handle keystrokes. Unfortunately much of the code that would provide context and clues is missing. Do you think you could include the whole procedure, and perhaps confirm how this is supposed to be working from the operator's perspective.

        Comment

        • Will James
          New Member
          • Dec 2011
          • 11

          #5
          jimatqsi, thanks for you example it works great, you say about error handling, would it be easy enough to stop the number going into minus numbers so it stops at '0'?

          NeoPa there was much info with the example I posted, the title just said Plus & Minus buttons, but no after some reading, I guess they were looking at using the keyboards +, - buttons!

          Comment

          • jimatqsi
            Moderator Top Contributor
            • Oct 2006
            • 1288

            #6
            Will, as for the logical limits on the values, that will be determined by your application's needs. What if there is nothing in the box to begin with? That is partly what I was referring to. But you should also add generic error handling that should be in every routine you make, something like this:
            Code:
            on error goto ErrLabelName  ' put this as 1st instruction
            ' then your routine should end with this:
            on error goto 0
            Exit Sub or Exit Function
            
            ErrLabelName:
               msgbox err.number & " " & err.description
               resume next
            
            end sub or end function
            Jim

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Keystrokes are much harder to make work sensibly. When you click on the button it's always clear what your intention is, but when you hit '-' for instance, you may be trying to decrement that paricular figure, or you may be typing something in another field EG. "I bought my groceries at the Co-Op". Your code (and design) would need to handle that.

              Comment

              Working...