PDA

View Full Version : Custome Date Picker! Duplicate value



mesakon
06-05-2018, 07:30 AM
I have a userform that includes 2 textboxes and 2 command buttons as it depicted in the picture.

22365


I downloaded the custom date picker (userform) from internet, and works perfectly. Problem is when I choose the date from commandbutton1 (calling the module), value appears in textbox1(from) but also in textbox2(to) as well. Additionally, when I use the commandbutton2(to) for date picking, value of textbox(from) is changing rather than textbox2(to). I couldn't figure out how to separate those textboxes with same custom date picker.

I used this code to transfer data from date picker to textbox. I know that 3rd should have been removed to not to duplicate same date in second textbox but I could not find any solution.

Private Sub cmdOkay_Click()
DateOut = SelectedDateIn
Questions.FromDate.Text = SelectedDateIn
Questions.ToDate.Text = SelectedDateIn

Me.Hide

End Sub

When I choose date from date-picker, values are storing in SelectedDateIn variable. Since I use the same variable for
both boxes, result is appearing in both and I could not figure out how to
create another variable to store different date values for same userform date picker.


Here is the link of date picker https://trevoreyre.com/portfolio/excel-datepicker/

SamT
06-07-2018, 04:25 PM
If TextBox1 = "" then
TextBox1 = SelectedDateIn
Else TextBox2 = SelectedDateIn

mesakon
06-08-2018, 12:03 AM
Thanks for this useful solution. However, one question is bothering me, what if user enter date for textbox1 and textbox2 and wants to change the date in textbox1 or textbox2?

SamT
06-08-2018, 08:19 AM
To Change an entered date, click the box to change, then use the DatePicker

This part goes at the top of the Form Code, before all subs
Dim FromSelected As Boolean
Dim ToSelected As Boolean


Private Sub TextBox1_Enter()
'As From TextBox
FromSelected = True
ToSelected = False
End Sub


Private Sub TextBox2_Enter()
'As To TextBox
FromSelected = False
ToSelected = True
End Sub


Sub Goes_In_Your_DatePicker_Code()

If TextBox1 = "" Then
TextBox1 = SelectedDateIn
ElseIf TextBox2 = "" Then
TextBox2 = SelectedDateIn
ElseIf FromSelected Then
TextBox1 = SelectedDateIn
ElseIf ToSelected Then
TextBox2 = SelectedDateIn
Else: MsgBox "Both Dates filled in. First select the Date you want to change... Etc."
End If

FromSelected = False
ToSelected = False

End Sub