Given a date in a txtbox return week number in another txtbox

sabas

New member
Local time
Yesterday, 20:44
Joined
Oct 20, 2016
Messages
4
Hello
In a Form I have written a statement to display the week number in TxtWeek from a date user writes in TxtDate.
Sub Week_Click()
If datDate = "0:00:00" Then
datDate = Date
Weel = DatePart("ww", datDate, vbMonday)
End Sub

However, any dates user types, Txtweek always returns 53.
I have been googling hours and hours with no success

Please, can someone fix my statement so it displays the correct week?:banghead:
 
I don't see where you set the variable equal to the textbox.
 
Here is an example. You need to get the date from the field first.
Also you need to close the "IF" or else the code will not work.
 

Attachments

Your code works correct.
I already checked the Required Variable Declaration unchecked
Thank you very much.
 
Wait are there people who turn that OptionExplicit off ?
Better keep it on and make the code clean and with no mistakes.
 
Turning it on was my recommendation. It would have flagged:

Weel = DatePart("ww", datDate, vbMonday)
 
Wait are there people who turn that OptionExplicit off ?
Better keep it on and make the code clean and with no mistakes.

I will always remember it.
Thank you very much indeed.
 

Users who are viewing this thread

Back
Top Bottom