1
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
Txt_Prod_Loc_Date.Value = MonthView1.Value
Unload Me
End Sub

Private Sub FrmCalendar_Initialize()
Unload Me
End Sub

I also tried Txt_Prod_Loc_Date.Value= DateClicked. But I see a " runtime error 424, object required

Thanks

Andrew Rayner
  • 1,056
  • 1
  • 6
  • 20
Abhi0609
  • 31
  • 2
  • 11
  • 1
    I don't have a `MonthView` control in my Excel. So, I can't be sure. Yet, your above code suggests that the variable `DateClicked` might contain the indicated date. Alternatively, I'd check the `.Value` of the control. Maybe the date is stored there `MonthView1.Value`? – Ralph Apr 11 '16 at 18:51
  • When I hover my mouse at DateClicked or MonthView1.Value in debug mode. I see the clicked date on the calendar. But, the value is not getting stored to my textbox. I taught when you do [textbox].Value= MonthView1.Value, the date should get stored to textbox. But, I don't see that happening. – Abhi0609 Apr 11 '16 at 20:01
  • BTW, even i did not have monthview in my tool box. I right clicked on tool box and got into additional control to select Microsoft MonthViewControl. – Abhi0609 Apr 11 '16 at 20:03
  • BTW, I wouldn't recommend using the MonthView Control :). You may want to see [This](http://stackoverflow.com/questions/12012206/formatting-mm-dd-yyyy-dates-in-textbox-in-vba/12013961#12013961) – Siddharth Rout Apr 12 '16 at 03:30
  • Thanks Siddarth. Useful one. – Abhi0609 Apr 12 '16 at 15:55

1 Answers1

1

You can use both; MonthView1.Value or DateClicked. The problem is not because of that :)

BTW why do you have Unload Me in FrmCalendar_Initialize()? That would give you a Run Time Error 91. Object Variable or With block variable Not set

You are getting Runtime error 424, object required because it could not find the Txt_Prod_Loc_Date control on your userform.

If that control is in the worksheet then use it like this

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    Sheet1.TextBox1.Value = MonthView1.Value
End Sub

If that control is in some other form (say Userform1) then use it like this

Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
    UserForm1.Txt_Prod_Loc_Date.Value = MonthView1.Value
End Sub
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
  • Thanks Siddharth Rout for your response. I had the textbox on a different User form. So with syntax like in your second option, the problem is solved. – Abhi0609 Apr 11 '16 at 20:37