Question about using the same 'get your own date' datepicker in multiple forms

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have been using the handy little 'get your own date' datepicker that I found here on this site sometime back and its been working great. However, I have to copy all of the code (both forms and modules) for the datepicker and paste them as new forms and modules (and renamed) if I want to use the same date picker but in separate form (the datepicker is a popup form that gets initiated when selecting a button on one of the main forms.)

so what I am trying to say is this:

I have several forms where I use a datepicker on each of them.

Each one of these forms uses a unique datepicker that is just a copy of the original one but with a different name.

This is because in the userform code for the 'get your own date' datepicker, and after a date has been selected, it directs the chosen date to a specific textbox on a specific form:

So I have this form ("frmIncidentEntry") and it uses the popup datepicker form that is named "ArrDateForm":
DatePicker1.PNG

And then I have another form ("frmIncidentEdit") that I use and for that one I have a copy of the ArrDateForm datepicker and it is named ArrDateFormEDIT:
DatePicker2.PNG

The code for both datepickers are the same, except for when the code is to take the previously chosen date and place it into a specific textbox on the main form, each uses the name of the form and the textbox name:
so for the first userform, I have pictured ("frmIncidentEntry") the date picker code for it looks like this (where "frmIncidentEntry.txtDateBox" is the textbox on the userform where the selected date is to be placed.):

VBA Code:
'DateSerial allows for international formats - DateValue does not.
 dteValue = VBA.DateSerial(Y, i, d)
 If GetKeyState(vbKeyShift) < 0 Then
    If Not IsEmpty(ActiveCell) Then
     'Using Str function will not add leading space.
      'ActiveCell.Value = ActiveCell.Value & " " & dteValue
    Else
      
    frmIncidentEntry.txtDateBox = dteValue
    frmIncidentEntry.txtDateBox = Format(dteValue, "mmmm, yyyy")
    
    End If
 Else
    
    frmIncidentEntry.txtDateBox = dteValue
    
 End If
 Me.Caption = VBA.UCase$(Format$(dteValue, "yyyy - mmmm ")) & d
 Me.Frame1.SetFocus
 Set objLB = Nothing
 Unload Me
 Exit Sub


And then for the other form ("frmIncidentEdit") that uses the same datepicker but with a different name, that code looks like this:
VBA Code:
'DateSerial allows for international formats - DateValue does not.
 dteValue = VBA.DateSerial(Y, i, d)
 If GetKeyState(vbKeyShift) < 0 Then
    If Not IsEmpty(ActiveCell) Then
     'Using Str function will not add leading space.
      'ActiveCell.Value = ActiveCell.Value & " " & dteValue
    Else
      
    frmIncidentEdit.txtDateBox1 = dteValue
    frmIncidentEdit.txtDateBox1 = Format(dteValue, "mmmm, yyyy")
    End If
 Else
    
    frmIncidentEdit.txtDateBox1 = dteValue
    
 End If
 Me.Caption = VBA.UCase$(Format$(dteValue, "yyyy - mmmm ")) & d
 Me.Frame1.SetFocus
 Set objLB = Nothing
  Unload Me
 Exit Sub
DoesNotFit:
 Application.Cursor = xlDefault
 MsgBox Err.Description & ".   ", vbExclamation, "Insert Date"
End Sub


It seems like there should be a much easier and more efficient way than to use seperate datepickers that are identical except for the name all because of 3 lines of code in each one that direct it to the form/textbox that it is to place the chosen date in.

Can I use the same exact Datepicker (ArrDateForm) for mulitple forms? How do I direct it (the popup ArrDateForm) so that it places the chosen date into the textbox on the form that is currently open (but behind the popup form?)

I have googled this in the past and researched this site looking for an answer/solution, but haven't come up with anything yet. Thanks for any suggestions.

-Keith


.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
It seems like there should be a much easier and more efficient way than to use seperate datepickers that are identical except for the name all because of 3 lines of code in each one that direct it to the form/textbox that it is to place the chosen date in.
I agree on that and would suggest to look for another datepicker. Perhaps this one is a better alternative ...
 
Upvote 0
I agree on that and would suggest to look for another datepicker. Perhaps this one is a better alternative ...
I was using this one from Trevor Eyre.. recently stopped working after reinstallation of excel.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top