date & spinbutton problem

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
384
Office Version
  1. 2019
Platform
  1. Windows
Hi

I have a textbox on a userform which is populated by a date in the format dd/mm/yy, from a worksheet, when the userform is initialised.

The following code is then used to increase or decrease the date as required.

'This procedure decrements the date shown in
'TextBox1 when you decrease the value of the
'SpinButton.

Private Sub SpinButton1_SpinDown()
On Error GoTo errortrap
DateSpin.Text = DateValue(DateSpin.Text) - 1

errortrap: Exit Sub
End Sub

'This procedure increments the date shown in
'TextBox1 when you increase the value of the
'SpinButton.

Private Sub SpinButton1_SpinUp()
On Error GoTo errortrap
DateSpin.Text = DateValue(DateSpin.Text) + 1

errortrap: Exit Sub

End Sub


This has worked for many months, but having just reinstalled windows, and I now find that when I alter the date using the spinbutton the format in the textbox changes to dd/mm/yyyyy.

Anybody got any ideas why this now happens?

Regards

Colin
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,402
Try changing the Windows Settings/Regional/Date short date format.
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Could be to do with Windows settings. Check Control Panel.

Otherwise I think this will solve the problem
Code:
DateSpin.Text = Format(DateValue(DateSpin.Text) + 1, "dd/mm/yy")
 

colinharwood

Active Member
Joined
Jul 27, 2002
Messages
384
Office Version
  1. 2019
Platform
  1. Windows
Thanks for the replies guys, Glenn was right, changed the setting and all is fine.

I thought it must be something in the Windows settings but my mind had gone blank after playing about with loads of settings in Excel.

Regards

Colin
 

Watch MrExcel Video

Forum statistics

Threads
1,118,052
Messages
5,569,897
Members
412,298
Latest member
dietitiann
Top