Consulting

Results 1 to 4 of 4

Thread: Custome Date Picker! Duplicate value

  1. #1

    Custome Date Picker! Duplicate value

    I have a userform that includes 2 textboxes and 2 command buttons as it depicted in the picture.

    Capture.JPG


    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/
    Last edited by mesakon; 06-05-2018 at 07:41 AM.

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    If TextBox1 = "" then
    TextBox1 = SelectedDateIn
    Else TextBox2 = SelectedDateIn
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    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?

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •