Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spin a button 1

Status
Not open for further replies.

DUF

Technical User
Mar 10, 2001
107
IE
Hi,
Does anyone know how to use the ActiveX spin Button control
on a form I have never used a ActiveX control in access and I want to use the spin button on a textbox that will hold a number that is not bound.

thanks for the help



duf
 
I never used it before, but playing around a little I came up with this:
Set up a spin button and a text box like this:
Code:
,-------------------,-----,
|                   |  ^  |
|                   |-----|
|                   |  v  |
'-------------------'-----'
Code:
        |              |
        |              |
      Text1        ActiveXCtl0
And set up code like this:
Code:
Option Explicit
Dim SpinValue As Integer

Private Sub ActiveXCtl0_Change()
  Text1.SetFocus
  Text1.Text = ActiveXCtl0.Value
  ActiveXCtl0.SetFocus
End Sub

Private Sub ActiveXCtl0_GotFocus()
  ActiveXCtl0.Value = SpinValue
End Sub

Private Sub ActiveXCtl0_LostFocus()
  SpinValue = ActiveXCtl0.Value
End Sub

Private Sub Text1_LostFocus()
  SpinValue = Text1.Text
End Sub
You should be able to bend that into something you can use.
 
Hi Zathras,

That worked thanks but it will not work with this format 2.45 it only operates with whole numbers is a way i can get it to work with the fraction part???

many thanks


Duf
 
Change Integer to Single or Double.

You're not alone,

TomCologne
 
Yes, it's just a matter of scaling the text box value.

Strange, but when I went back into the code, the GotFocus/LostFocus events wouldn't fire. So I re-wrote it this way to get it to work again:
Code:
Option Compare Database
Option Explicit
Dim SpinValue As Integer
Dim InhibitChange As Boolean

Private Sub ActiveXCtl0_Change()
  If Not InhibitChange Then
    InhibitChange = True
    SpinValue = ActiveXCtl0.Value
    Text1.SetFocus
    Text1.Text = SpinValue / 100
    ActiveXCtl0.SetFocus
    InhibitChange = False
  End If
End Sub

Private Sub Text1_Change()
  If Not InhibitChange Then
    InhibitChange = True
    SpinValue = Int(Text1.Text * 100)
    ActiveXCtl0.SetFocus
    ActiveXCtl0.Value = SpinValue
    Text1.SetFocus
    InhibitChange = False
  End If
End Sub
Set the Max property on the spin button to 1000 (or whatever it should be) to represent a max value of 10.00
Set the Min (if appropriate) and an initial value (if desired).

 
hi
Thanks for the reply I did try to change the Integer to Double with the first code but it did not have an effect,
Your new code will not allow the ActiveXctl value to be set
I need the decimal.

thanks


Duf
 
How are you setting the ActiveXctl value?

To set it for "2.45" you would need to set it for 245 since it only accepts integer values, and in order to set it to 245 you would have to set the max value to a number greater or equal to 245.
 
Hi,
Thats fine I did not know that the activeXclt can only be an interger, I will play around with it later.Thanks for your help.


duf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top