Plus/Minus Button for Any Numeric Box on Form

rlangford

Registered User.
Local time
Yesterday, 19:26
Joined
Feb 5, 2014
Messages
17
Hello all,
I'm working on a form that I want to insert a plus button/minus button.I am aware of the vba code numbers 107 and 109 if you want to use the actual keys but I would rather use a button.

I made a button and here is the code I used now. This code is numeric box specific. So it only adds one to the MileageStart numeric field. (Additionally you can put a minus in to subtract one).

Private Sub Command153_Click()
MileageStart = MileageStart + 1
End Sub

Instead of having a bunch of these buttons all over boxes on my form is there some code that I can use to "select" a text box and just have the Plus/Minus button on the form header that I would hit and it would add or subtract (and then I could go to another box select it and hit Plus/Minus and so forth).

Thanks in advance, have a great day!
 
For your code, see if PreviousControl helps you out.
 
Thanks guys, I guess I'm not sure how I could implement either of those.

If I use spin buttons can I use 1 set of buttons to do an entire form? If so what would the code look like? Would it reference the form?

And I tried the code PreviousControl and it didn't work. However I don't think that is how it is suppose to be used. I cannot figure out how it suppose to be used after reading more about it. Any help would be great!

Private Sub Command153_Click()
PreviousControl = PreviousControl + 1
End Sub
 
Screen.PreviousControl = Screen.PreviousControl + 1
 
Just to finalize it for others to see the full code snippet that works is as follows:

Private Sub PlusButton_Click()
Screen.PreviousControl = Screen.PreviousControl + 1
End Sub

You could do a minus button with the opposite:

Private Sub MinusButton_Click()
Screen.PreviousControl = Screen.PreviousControl - 1
End Sub

Thanks again pbaldy!
 
Happy to help!
 
One more question. When using this code:
Private Sub MinusButton_Click()
Screen.PreviousControl = Screen.PreviousControl - 1
End Sub

Private Sub PlusButton_Click()
Screen.PreviousControl = Screen.PreviousControl + 1
End Sub

When I am selecting a cell and am using the plus button and and then switch to the minus button (without leaving the box) after just using the plus I get this error.

Run-time error '438':
Object doesn't support this property or method.

I feel like I need a stop line of code or a separator. I don't think this is that hard. By the way the same thing happens with the minus if I immediately hit the plus. Maybe it needs a refresh or something.

A part time fix is just to click on another cell then back into that one and use the minus then.

Any code help would be great!
 
You can probably trap for it:

http://www.baldyweb.com/ErrorTrap.htm

The problem when clicking plus then minus (or probably even plus again) is that the previous control at that point is the plus button.
 

Users who are viewing this thread

Back
Top Bottom