![]() |
Date Control using Spinner
Hello All,
Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
although you have a lot of code you don't need, it worked fine for me.
xl2000 -- Regards, Tom Ogilvy "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
Cheers Tom,
I find it strange it works for you and not me. How would you write the code to do this? I'm definitely baffled now! s "Tom Ogilvy" wrote: although you have a lot of code you don't need, it worked fine for me. xl2000 -- Regards, Tom Ogilvy "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
Are you using dd/mm/yyyy format.
this may be why it is working for me and not for you. Anyway, cdate should work regardless: Private Sub SpinButton2_Spinup() Dim SD2 As Date If TextBox1.Value = "" Then TextBox1.Value = FormatDateTime(Date, vbShortDate) Else SD2 = CDate(TextBox1.Value) + 1 TextBox1.Value = FormatDateTime(SD2, vbShortDate) End If End Sub -- Regards, Tom Ogilvy "Stan" wrote in message ... Cheers Tom, I find it strange it works for you and not me. How would you write the code to do this? I'm definitely baffled now! s "Tom Ogilvy" wrote: although you have a lot of code you don't need, it worked fine for me. xl2000 -- Regards, Tom Ogilvy "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
Stan,
Are you in the UK? It goes crazy for me as well, it's a date thing I think where VBA reverts to US style dates whatever the short date style (you see this as 1st Jul shows as 07/01/2004), which would also explain why it works for Tom. This works for me Private Sub SpinButton2_Spinup() SD = Date If TextBox1.Value = "" Then TextBox1.Value = Format(Date, "dd/mm/yyyy") Else If Not TextBox1.Value = "" Then SD2 = DateAdd("d", 1, CDate(TextBox1.Value)) TextBox1.Value = Format(SD2, "dd/mm/yyyy") End If End If End Sub -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
Thanks again Tom - that's crackin!
Stan "Tom Ogilvy" wrote: Are you using dd/mm/yyyy format. this may be why it is working for me and not for you. Anyway, cdate should work regardless: Private Sub SpinButton2_Spinup() Dim SD2 As Date If TextBox1.Value = "" Then TextBox1.Value = FormatDateTime(Date, vbShortDate) Else SD2 = CDate(TextBox1.Value) + 1 TextBox1.Value = FormatDateTime(SD2, vbShortDate) End If End Sub -- Regards, Tom Ogilvy "Stan" wrote in message ... Cheers Tom, I find it strange it works for you and not me. How would you write the code to do this? I'm definitely baffled now! s "Tom Ogilvy" wrote: although you have a lot of code you don't need, it worked fine for me. xl2000 -- Regards, Tom Ogilvy "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
Date Control using Spinner
"Stan" wrote: Thanks again Tom - that's crackin! Stan "Tom Ogilvy" wrote: Are you using dd/mm/yyyy format. this may be why it is working for me and not for you. Anyway, cdate should work regardless: Private Sub SpinButton2_Spinup() Dim SD2 As Date If TextBox1.Value = "" Then TextBox1.Value = FormatDateTime(Date, vbShortDate) Else SD2 = CDate(TextBox1.Value) + 1 TextBox1.Value = FormatDateTime(SD2, vbShortDate) End If End Sub -- Regards, Tom Ogilvy "Stan" wrote in message ... Cheers Tom, I find it strange it works for you and not me. How would you write the code to do this? I'm definitely baffled now! s "Tom Ogilvy" wrote: although you have a lot of code you don't need, it worked fine for me. xl2000 -- Regards, Tom Ogilvy "Stan" wrote in message ... Hello All, Ok, I have a text box with the current date in, and require a spinner to increase/decrease the date. I have managed to get it to work, however once the date gets passed the end of the month, the date that's displayed in the textbox goes crazy! The code I have used (for the spinup button) is shown below: Private Sub SpinButton2_Spinup() SD = Date SD = FormatDateTime(Date, vbShortDate) If TextBox1.Value = "" Then TextBox1.Value = Date TextBox1 = FormatDateTime(TextBox1.Value, vbShortDate) Else If Not TextBox1.Value = "" Then SD2 = TextBox1.Value TextBox1.Value = FormatDateTime(SD2, vbShortDate) SD2 = DateAdd("d", 1, SD2) TextBox1.Value = SD2 TextBox1.Value = FormatDateTime(TextBox1.Value, vbShortDate) End If End If End Sub Does anyone know how to get the spinner to increase/decrease the date simply day by day, changing as it should throughout the year? Any help on this would be greatly appreciated. Thanks in advance, Stan |
All times are GMT +1. The time now is 12:31 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com