• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel 2013 DatePicker to Control Multiple Textboxes in multiple Userforms

Excelnoub

Member
Good day,
I have been looking everywhere for the following code or if there is any.

I have multiple Userforms...all that will all have multiple textboxes. In each Userform there will be around 3 Textboxes that will need control vs. a DatePicker. Another Userform that will need control on 4 Textboxes with Date entries.

I have it set up that I have individual Calendars DatePicker controlling individual Textbox from one userform. Therefore if I have 4 textboxes to have individual date entry in one userform, I will have 4 different Calendar Userform. This is getting ridiculous.

I need to know if there is a General method that I could control all my textboxes from any Userforms to manipulate date entries.

Example: I am using, in my Userform, "frmdata" Textbox2_Enter and Textbox_Change method.

On enter to "frmCal1.Show so that if I select a textbox it will generate the date picker... I have my Date Picker the same method as Canlendar Control 2007.

Any who, is there any way, code, that will control any textbox that I say to be date entries and not to have, like 10 000 calendar userform?

So if I need 10 Textboxes to be control by one calendar then only to have my Sub...Enter() and have the date populate this textbox by not affecting other Textbox from this userform or in any Userform?
 
Last edited:
Nothing Right now that would control any Textboxes from Any Userforms...

I would love to have it like a Clear All:

Code:
Option Explicit

Public Function ClearAll(frm As MSForms.UserForm) As Boolean
    ' clear out all controls
    Dim Octrl    As Control
    ' if any error occurs, just exit
    On Error GoTo ExitFunc
  
    ' loop through controls, figure out type and
    ' use appropriate method to clear it
    For Each Octrl In frm.Controls
        Select Case TypeName(Octrl)
        Case "TextBox":  Octrl = Empty
        Case "CheckBox", "OptionButton": Octrl.Value = False
        Case "ComboBox", "ListBox": Octrl.ListIndex = -1
Case Else:
        End Select
    Next Octrl
  
ExitFunc:
    Set Octrl = Nothing
End Function

If you look at this code it will clear all the data from a single userform's control. So any information that you have in a userform, Textbox, Combobox or Checkbox in this case, will be cleared.

Ilove this code... Has nothing to do with what I am trying to do but some of the code would work the same. If any Userform is activated I need to, If I decide to add Textbox1 and textbox2 from my frmdata Userform to be able to add dates from a pop up datepicker, then that code will be able to see that Iam making one selection and not populating all of the controls.

I had this in my workbook:

Calendar Userform:
Code:
Private Sub Calendar2_Click()
    frmne.TextBox3.Value = Format(Calendar2.Value, "yyyy/mm/dd")
    Unload Me
End Sub

Private Sub Calendar2_DateClick(ByVal DateClicked As Date)
  On Error Resume Next
  Texbox.Value = DateClicked
  Unload Me
End Sub

Private Sub Cmdclose_Click()
    Unload Me
End Sub

Private Sub UserForm_Activate()
Me.Calendar2.Value = Date
End Sub

Userform frmne
Code:
Private Sub TextBox3_Enter()
  frmne.TextBox3.Value = ""
  frmCalendar2.Show
End Sub

But in the end this is only controlling one textbox. I have 5 Userforms and within these 5 userforms I have up to 5 date entries to populate.

This means that Iwould have to create a Calendar (or datepicker) for each individual Controls.

I am looking on the web and nothing even comes close to what I am looking for. I am not very good in VB Coding but trying to come up with something better than having 50 Datepicker Userforms to individually control my needs.

I mean there must be a solution out there that could facilitate my task. Just haven't pin pointed it yet :(
 
Hi ,

I am not sure what your problem is ; can you see the uploaded file ?

It references the Microsoft Calendar Control 2007.

Narayan
 

Attachments

  • Popup Calendar.xlsm
    18.4 KB · Views: 69
Here would be an example:

If you click on the Command_Button in Sheet1 you will see the Userform... I need to indivually control all Textbox for date entry using one MonthView, sorry was using datepicker, with one monthview userform.

If you double click A1 through A1000 on the sheet itself you will generage the calendar to call frmCalS and on date selection, populate the cell.

I need this for individual Textboxes in my frmdate userform. When I click on a textbox, and when the calendar is called, to insert the date selected. But everytextbox must be controlled individually.
 

Attachments

  • Testdate.xlsm
    23.2 KB · Views: 68
I don't have Calendar Control anymore as I switched to Excel 2013. But I will play around with your code to see if I can't implement it in my Userform.
 
NARAYANK991 I have been waiting for this for like one year lol you have just made my month...year.

I haven't got an answer on this since the beginning and voila.

I cannot thank you enough for this.

Hui: Thank you for adding this to the blog. Hopefully this will help others out there to see that it is possible :)

ExcelNoub
 
Back
Top