date issue

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

date issue

Post by saiprasad »

Hi ,

In my userform, I have two date picker. First datepicker will show the log in date and second datepicker which is DTPicker2 should show the first date picker value + 8 days.

I am using the below formula in the second date picker but it seems it does not work. Any idea?

Thanks :)

Me.DTPicker2.Value = "Me.DTPicker1.Value + 8 days"

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: date issue

Post by Rudi »

Try this: (untested)

Me.DTPicker2.Value = DATEVALUE(Me.DTPicker1.Value) + 8 " days"
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Rudi,

Thanks for your reply. Nope... its not working :(

thanks

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

Try this instead:

Me.DTPicker2.Value = Me.DTPicker1.Value + 8

or

Me.DTPicker2.Value = DateAdd("d", 8, Me.DTPicker1.Value)
Best wishes,
Hans

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: date issue

Post by Rudi »

I forgot the ampersand...
Try either one...

Me.DTPicker2.Value = DATEVALUE(Me.DTPicker1.Value) + 8 & " days"

Me.DTPicker2.Value = DATESERIAL(YEAR(Me.DTPicker1.Value),MONTH(Me.DTPicker1.Value),DAY(Me.DTPicker1.Value) + 8) & " days"

Ahhh...of course...the DateAdd function. Good one Hans!
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Thanks Hans,

Its working.

Thanks rudi :)

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans and Rudi,

Regarding this issue, my datepicker is working only in the list box.

Me.DTPicker2.Value = DateAdd("d", 8, Me.DTPicker1.Value)

but , when i double click the userform to edit any of the value it does not getting update unless i search via listbox.

I tried to add the below code in the DTPicker2 but it seems its not working. any idea?

Dim wsh As Worksheet
Dim r As Long
Set wsh = Worksheets("Sheet1")
r = Me.DTPicker1
If IsDate(Me.DTPicker1.Value) Then
Me.DTPicker2.Value = DateAdd("d", 2, Me.DTPicker1.Value)
End If

Thanks :)

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

I think you'll need to set the value of DTPicker2 in the UserForm_Initialize event procedure of the userform.
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans,

Thanks for your reply. How do you do that please

thanks

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

I assume that you have a line in UserForm_Initialize to set the value of DTPicker1. Please post that line.
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans,

no i did not add any thing in the userform_initialize

thanks

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

I'll have to see the workbook - otherwise it's impossible for me to know what's happening.
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans,

Private Sub UserForm_Initialize()
Me.DTPicker3.Value = DateAdd("d", 23, Me.Week1.Value)
End Sub

thanks :)

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

OK, that code sets the value of DTPicker3. But how does DTPicker1 get its value?
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans,

DTPicker1 using the same concept

Private Sub UserForm_Initialize()
Me.DTPicker1.Value = DateAdd("d",12,Me.Week1.Value)
End sub

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

Try this:

Me.DTPicker2.Value = DateAdd("d", 14, Me.Week1.Value)

Change the value 14 as needed.
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Hi Hans,

Thanks for your reply. I tried that as well. Its not working.

Is my userform_initialize() is correct? or do i need to change it?

Me.DTPicker1.Value = DateAdd("d",12,Me.Week1.Value) is working fine in the listbox but it does not work if the listbox is not clicked.

thanks again

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: date issue

Post by HansV »

I repeat: I'll have to see the workbook. I can't offer further help without that.
Best wishes,
Hans

saiprasad
2StarLounger
Posts: 148
Joined: 18 Jun 2015, 09:46

Re: date issue

Post by saiprasad »

Thanks a lot for your help. I will put the workbook after little modification.

Thanks :)