View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Spinbutton help required

Just add this

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

SpinButton1.Value = TextBox1.Text
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"N E Body" wrote in message
...
Many thanks Tom

I have got it working on my userform apart from 1 problem which I cannot
fix.

If I enter a number into TextBox2 then click spinup/down I would like the
number in textbox2 to advance/decrease by one.
With my code TextBox2 is populated with a low number then spins from that
number!

How do I correct this?

Sample of my code below

Many thanks

Kenny

Private Sub UserForm_initialize()

SpinButton1.Max = 3000
SpinButton1.Min = 4
SpinButton1.Value = 4

End Sub



Private Sub SpinButton1_SpinUp()

idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With

ans = LogEntry.TextBox2.Value
res = Application.Match(CLng(ans), Range("A4:A3000"), 0)
Range("A4:A3000")(res).Activate

IdentRetrieve1

End Sub



Private Sub SpinButton1_SpinDown()

idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With

ans = LogEntry.TextBox2.Value
res = Application.Match(CLng(ans), Range("A4:A3000"), 0)
Range("A4:A3000")(res).Activate

IdentRetrieve1

End Sub






"Tom Ogilvy" wrote in message
...
There is no trick to it.

Use the spinup and spindown events to increment an index into your range

and
retrieve the value. Assign the retrieved value to the textbox. Set

the
min and max values so the spinbutton will not go outside your range.

Private Sub SpinButton1_SpinUp()
idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub
Private Sub SpinButton1_SpinDown()
idex = SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub


Private Sub UserForm_Initialize()
SpinButton1.Max = 20
SpinButton1.Min = 1
SpinButton1.Value = 10
End Sub


The buttons in this case work opposite of the rows (spindown increases

the
row addressed). However, with increasing values in the cell, it works

OK
depending on your perspective. However, if you want to have spinup

decrease
the row (arrow points in the direction of row change), you can use

Private Sub SpinButton1_SpinUp()
idex = 21 - SpinButton1.Value
With Worksheets(1)
TextBox2.Text = .Range("A1")(idex)
End With
End Sub

as an example (similar change in SpinDown).


--
Regards,
Tom Ogilvy

"N E Body" wrote in message
...
Hello everyone

Can anyone direct me to a site where I can learn how to code a spin

button?
I have not used one before and I have not got a clue where to start!

I want to use it in the following manner,

I have an Excel database that has a userform for entering and

retreiving
data. The form has several fields - one of which is TextBox2 which

shows
the entry number.
I would like to add a spinner to TextBox2 so I can select the previous

or
next entry and show the details in the other fields.

I would be glad of any advice!

Kenny

Win 2000 and Millennium
Excel 97 and 2000