lucavilla
asked on
VBA: how to return a value from a pick-a-date-frmo-calendar sub
I successfully used the following code in a VBA script to let the user pick a date from a calendar:
Question is: how can I read that value DateClicked from another sub?
If I launch the MsgBox (DateClicked) inside the sub above I see a date, while
If I launch it from another sub I see an empty msgbox :(
Private Sub MonthView1_DateClick(ByVal DateClicked As Date)
On Error Resume Next
MsgBox (DateClicked)
Unload Me
End Sub
Question is: how can I read that value DateClicked from another sub?
If I launch the MsgBox (DateClicked) inside the sub above I see a date, while
If I launch it from another sub I see an empty msgbox :(
ASKER
A msgbox(dClick) in another sub display a "00:00:00" :(
Did you activate the click event on MonthView1 before you called the other sub?
ASKER
hmm no, how do I do it?
click on the MonthView1 component you put on the sheet and select a date
ASKER
Not sure if I understood, I just created a button and assigned to it a macro named MySub that calls the calendar with this command:
UserForm1.Show
After the user selects a date, the calendar sub MonthView1_DateClick ends with an "Unload Me" and all the other instructions after "UserForm1.Show" of MyMacro are executed.
The problem is that I cannot read the date from these following commands in MySub.
I can only read it from inside the MonthView1_DateClick sub.
UserForm1.Show
After the user selects a date, the calendar sub MonthView1_DateClick ends with an "Unload Me" and all the other instructions after "UserForm1.Show" of MyMacro are executed.
The problem is that I cannot read the date from these following commands in MySub.
I can only read it from inside the MonthView1_DateClick sub.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works wonderfully! Thanks!
In UserForm1 I wrote:
Public Sub MonthView1_DateClick(ByVal dateClicked As Date)
On Error Resume Next
dClick = dateClicked
Unload Me
End Sub
In Module1 I wrote:
Public dClick As Date
Sub Aggiorna_dati_consulenza()
UserForm1.Show
MsgBox (dClick)
End Sub
Msgbox correctly show the selected date "17/07/2014"!
In UserForm1 I wrote:
Public Sub MonthView1_DateClick(ByVal
On Error Resume Next
dClick = dateClicked
Unload Me
End Sub
In Module1 I wrote:
Public dClick As Date
Sub Aggiorna_dati_consulenza()
UserForm1.Show
MsgBox (dClick)
End Sub
Msgbox correctly show the selected date "17/07/2014"!
Open in new window