SpinButton

T

TerryM

I have unbound integer value on a form which I would like to be
increment/decrement quickly. I was hoping to use the 'SpinButton' but this
appears to only use a bound value.
How can I (or is it even possible to) increment/decrement an unbound value
by simply holding down a button on the form or can I, for example, hold down
the '+' or '_' keys to do the same?
I would welcome any suggestions.
Terry
 
J

Jana

I have unbound integer value on a form which I would like to be
increment/decrement quickly. I was hoping to use the 'SpinButton' but this
appears to only use a bound value.
How can I (or is it even possible to) increment/decrement an unbound value
by simply holding down a button on the form or can I, for example, hold down
the '+' or '_' keys to do the same?
I would welcome any suggestions.
Terry

I'm using A97, so I don't have a spin control available, but here's
how you can do it with an unbound text box:

Create an unbound text box, with the following properties:
Default Value: 1 (or whatever # you want to start at)
Name: txtTheNum
Locked: Yes
Enabled: Yes

On your form properties, change the Key Preview property to Yes
Right click in the On Key Press Event of the form, choose "Build",
then Code Builder and paste this text where the cursor is:
If KeyAscii = 43 Then
Me.txtTheNum = Me.txtTheNum + 1
ElseIf KeyAscii = 45 Then
Me.txtTheNum = Me.txtTheNum - 1
End If

Close the Class Module window, then save your form. You will need to
use the + and - keys on your number pad and you should see your number
increase and decrease as you requested.

HTH,
Jana
 
J

Jana

I have unbound integer value on a form which I would like to be
increment/decrement quickly. I was hoping to use the 'SpinButton' but this
appears to only use a bound value.
How can I (or is it even possible to) increment/decrement an unbound value
by simply holding down a button on the form or can I, for example, hold down
the '+' or '_' keys to do the same?
I would welcome any suggestions.
Terry

Terry:

I previously posted, so pardon if this shows up again:

I use A97, so I don't have a 'spin' control. But here's how you'd do
it with an unbound text box:

1. Create a text box and set the following properties:
Name: txtTheNum
Enabled: Yes
Locked: Yes
Default Value: 1 (or whatever starting number you want)

2. Go to the properties of your Form and set the following property:
Key Preview: Yes

3. Right click in the On Key Press Event of your Form (NOT the text
box!) and choose "Build" then "Code Builder". Paste the following
into the module (don't move the cursor!):
If KeyAscii = 43 Then 'User pressed + on the number pad
Me.txtTheNum = Me.txtTheNum + 1
ElseIf KeyAscii = 45 Then 'User pressed the - on the number pad
Me.txtTheNum = Me.txtTheNum - 1
End If

Close the Class Module Window.
Save your Form.
Open your form, and hit the + key on your number pad, see your number
go up. Hit the - key on your keyboard and see the number go down.

HTH,
Jana
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top