PDA

View Full Version : Solved: spinbutton on date textbox



av8tordude
02-15-2011, 10:39 AM
I have a date textbox and I have added a spinbutton to move the date up or down. My code causes an error each time I click the spinbutton. Can some assist. Thanks

Date1.Value = Format(Date1.Value + SpinButton1, "mm/dd/yy")

Note: I don't use datepickers or calendar control b/c some users don't have them installed on the computers.

Tinbendr
02-15-2011, 10:47 AM
date1.Value = Format(CDate(date1.Value) + SpinButton1, "mm/dd/yy")

But I think you want
Private Sub SpinButton1_SpinDown()
date1.Value = Format(CDate(date1.Value) - 1, "mm/dd/yy")
End Sub
Private Sub SpinButton1_SpinUp()
date1.Value = Format(CDate(date1.Value) + 1, "mm/dd/yy")
End Sub

David

av8tordude
02-15-2011, 10:56 AM
Thank you David. The first option worked perfect.

I was able to figure out how to make the calendar to move up or down by changing the spinbutton properties min value to -365. I did run across your second suggestion, but I found the properties option worked best for my situation.