By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,720 Members | 2,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,720 IT Pros & Developers. It's quick & easy.

Plus & Minus Buttons

P: 11
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
Dec 5 '11 #1

✓ answered by jimatqsi

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:
Expand|Select|Wrap|Line Numbers
  1. me!nameoftextbox = me!nameoftextbox-1
or +1 instead of -1

plus you may want to add some error handling.

Jim

Share this Question
Share on Google+
6 Replies


Expert 100+
P: 1,221
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:
Expand|Select|Wrap|Line Numbers
  1. me!nameoftextbox = me!nameoftextbox-1
or +1 instead of -1

plus you may want to add some error handling.

Jim
Dec 5 '11 #2

P: 11
Hi there

This is the code I found:

Expand|Select|Wrap|Line Numbers
  1.     If KeyCode = 107 Then
  2.         Me.Text1 = Me.Text1 + 1
  3.         KeyCode = 0
  4.     ElseIf KeyCode = 109 Then
  5.         Me.Text1 = Me.Text1 - 1
  6.         KeyCode = 0
  7. End If
I changed the text1 to the name on my field
Dec 5 '11 #3

NeoPa
Expert Mod 15k+
P: 31,489
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.
Dec 6 '11 #4

P: 11
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!
Dec 6 '11 #5

Expert 100+
P: 1,221
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:
Expand|Select|Wrap|Line Numbers
  1. on error goto ErrLabelName  ' put this as 1st instruction
  2. ' then your routine should end with this:
  3. on error goto 0
  4. Exit Sub or Exit Function
  5.  
  6. ErrLabelName:
  7.    msgbox err.number & " " & err.description
  8.    resume next
  9.  
  10. end sub or end function
Jim
Dec 6 '11 #6

NeoPa
Expert Mod 15k+
P: 31,489
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.
Dec 6 '11 #7

Post your reply

Sign in to post your reply or Sign up for a free account.