User Form day name from date

FlashNZ

New Member
Joined
Mar 3, 2021
Messages
29
Office Version
  1. 365
Platform
  1. Windows
I have built a user form and I have DTPicker1 where the user can select a date. I have a text box called tbSearchDay that I would like it to automatically display the day of the week once a date is selected in DTPicker1.

How to make this happen, thanks in advance?

Gordon
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Perhaps in textbox AfterUpdate event

If Not Me.DTPicker = "" Then tbSearchDay = Format(DTPicker,"dddd")

You might require other validation such as ensuring the entry is a valid date. Results might depend on which date format you're using - US or not.
 
Upvote 0
Perhaps in textbox AfterUpdate event

If Not Me.DTPicker = "" Then tbSearchDay = Format(DTPicker,"dddd")

You might require other validation such as ensuring the entry is a valid date. Results might depend on which date format you're using - US or not.
Thanks, it works, nearly. If I select a date in DTPicker1 then nothing appears in tbSearchDay until I enter a value into tbSearchDay it then shows the day of the week correctly. How do we make this happen automatically?
 
Upvote 0
Post your code so I have something to look at? Please use code tags (vba button on posting toolbar).
 
Upvote 0
Sorry here it is:

Code:
Private Sub tbSearchDay_AfterUpdate()
If Not Me.DTPicker1 = "" Then tbSearchDay = Format(DTPicker1, "dddd")
End Sub
 
Upvote 0
If I select a date in DTPicker1 then nothing appears in tbSearchDay until I enter a value into tbSearchDay
Until you posted the code I had no real idea if you were using the right event or not. So you actually have to start entering something in the textbox that you want the code to update? That sounds like the update event isn't firing as desired. If you pick a date and it goes into the date textbox, will the other one not show the day value when you click out of the date textbox? Perhaps click into some other control or on the form itself to test.
 
Upvote 0
Until you posted the code I had no real idea if you were using the right event or not. So you actually have to start entering something in the textbox that you want the code to update? That sounds like the update event isn't firing as desired. If you pick a date and it goes into the date textbox, will the other one not show the day value when you click out of the date textbox? Perhaps click into some other control or on the form itself to test.
Hi, it appears from looking online it is an issue with the Date Picker control. I created a text box and if I refer to that text box and enter a date into it updates the day automatically.

Thanks for your help.
 
Upvote 0
Ahh, so I'm familiar with the date picker option in an Access textbox and assumed it would be the same in Excel. Silly me to think that 2 divisions of M$ might be on the same page with features. In Access, if you elect to show date picker for dates, whatever you choose from the calendar picker that pops up goes right into the textbox.
Glad you figured it out.
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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