It's called an UpDown control, and you get to it through the "More Controls" icon in the toolbox that has your label, textbox, command button, etc. (See picture.)
Then, look at the properties. The most important one is Buddy Control. That's the textbox you set to match the arrows so that when you click up, it increments the value in the Buddy Control textbox, pressing down decrements it, etc.
There are also Major/Minor Increment properties. The minor is the "one click" interval of the number, and the "Major" is the "hold the mouse button on an arrow" interval.
I decided to do the up down control as it seems easier. But I get a problem when I get to the buddy control. What should I do next? (ie what do i type in the box?)
Is the UpDown Control 2007's version of the old SpinButton Control?
And while we're on the subject, just a reminder that ActiveX controls can be very problematic when moving between versions of Access. This problem is avoided with simple buttons with code like Bob's or even something like this
Code:
Private Sub YourNumericField_KeyPress(KeyAscii As Integer)
If KeyAscii = 43 Or KeyAscii = 61 Then
Me.YourNumericField = Nz(Me.YourNumericField, 0) + 1
KeyAscii = 0
ElseIf KeyAscii = 45 Or KeyAscii = 95 Then
Me.YourNumericField = Nz(Me.YourNumericField, 0) - 1
KeyAscii = 0
End If
End Sub
which, when the form's Key Preview is set to Yes, allows you to increment/decrement a field just using the =/- keys.
It's asking you for the name of the control that will be affected by pressing the up/down buttons. Make a textbox, put it next to the up/down control however you want, and then name that control something obvious and type in the name of that control into the Buddy Control name. Example:
Name the UpDown control updnMyValue.
Name the textbox control txtMyValue.
In the Buddy Control shown in the picutre posted, type in txtMyValue.
Moniker, thanks, I followed what you did, and I think I managed to link it. But the problem is when I click the up/down button, it doesnt increase/decrease the value. Any help?
sorry, now my access if messed up, I tried checking sync and doing alot of other ways, but all failed. There also seems to be a glitch,sometimes when I did the steps correctly as Moniker provided, the sync buddy and buddy property cant be edited at all.
i am going to be really cheeky, but if possible, can someone do a sample db with up and down control and upload it rapidshare.de for me?
Perhaps Moniker can post a sample db with it as even I haven't been able to get it to work for me. I've used it before in VB apps, but not in an Access database. I usually just use buttons and my own code behind them for Access db's.
1. What button is he talking about? command or toggle button?
2. how do I add vba coding to my buttons? srry I am a newbie.
Make two buttons, "cmdIncrementLessons" and make the caption "+", and "cmdDecrementLessons" with the caption "-". Then add this VBA code:
Code:
Private Sub cmdIncrementLessons_Click()
Me![lessons] = [lessons] + 1
End Sub
Code:
Private Sub cmdDecrementLessons_Click()
Me![lessons] = [lessons] - 1
End Sub
This is the simplest way to do it. There are others, let me know if you want to see them...
You shouldn't call a filed "number of lessons attended", so I changed it to "lessons". I guess you could call it "NoLessonsAttended" or something similar.
Edit; you might want to add validation to these, especially the decremental one because you don't want it to go below '0' attendees.