Strange Calendar control formatting issue

philfloyduk

Board Regular
Joined
Jan 6, 2011
Messages
82
Hi.

I have a repair booking UserForm that uses Calendar control 12.0. I've used the code below to format it to dd/mm/yyyy which works if you're selecting a date within the current month, but not if you're selecting a date from another month. For example, with today being 24th Feb, if I select 25/02/2011 it'll format correctly. However, if I select 01/03/2011 (which is likely to happen toward the end of the month) it won't format it.

Thanks in advance for any help offered

Private Sub Calendar1_Click()
appdateTextBox.Value = Calendar1.Value
appdateTextBox.Text = Format(appdateTextBox.Text, "dd/mm/yyyy")
Calendar1.Visible = False
apptimeTextBox.SetFocus
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
try making month mmm not mm 1/3 and 3/1 look different, but it will never mistake Jan for Mar
 
Upvote 0
Thanks for your reply.

I've tried your method but I just get the name of the month in short display. So if I select the 10th March I get 3-Oct-2011, but the dates in Feb are now also the wrong way around.
 
Upvote 0
Replace 2 lines of code:
appdateTextBox.Value = Calendar1.Value
appdateTextBox.Text = Format(appdateTextBox.Text, "dd/mm/yyyy")


by this single line:
appdateTextBox.Value = Format(Calendar1.Value, "dd/mm/yyyy")
 
Upvote 0
Glad it helped, Phil.

Excel treats the date, which is in the text format, using its own sense in recognition of day and month.
But if date value is in the date (i.e. numeric) format, then it never confuse the day with month.
The calendar control returns value in the date (numeric) format, thus the direct formatting of that value is correct always.

Kind Regards,
Vlad
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top