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":
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:
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.):
And then for the other form ("frmIncidentEdit") that uses the same datepicker but with a different name, that code looks like this:
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
.
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":
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:
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
.