mdeanh5252
New Member
- Joined
- Sep 5, 2016
- Messages
- 32
- Office Version
- 365
- 2010
- 2007
- Platform
- Windows
I have been trying out different variation of class image event handlers that have not given me good results.
I am using the date picker created by Trevor Eyre and want to use the date picker with 14 separate calendar images (Image1, Image2, etc..) to populate the date variable to the textbox adjacent to the image.
I have for now an event handler for every Image1_mousedown event that works however I hoped to utilize a class event handler that can simplify things.
The textboxes names I am populating are not in sequence from each other (1, 2, 3, etc..) they are all different numbers (textbox9, 33, 50, etc..)
Side note: I modified the date picker to show up center of the screen where workbook is displaying (multiple monitors) however would be nice it was relative to the mouse position for where it clicked the image for example just right of the image size or something. I am sure this is possible just a bit over my head at the moment.
I am hoping someone out there has a code that can be effective to capture the ImageCtrl.name and give the corresponding textbox in my case (textbox9, 33, 50, 55, etc..) the date variable.
Please note: Yes I renamed my textbox controls to Date1, Date2, etc.. for a test, and figured id need figure out a loop similar to the Userform_Initialize code below that will rename my textboxes back to their original name (textbox9, 33, 50, 55, etc..) by utilizing the textbox.tag to recall the old name as I have a loop that runs to save all my controls values to a worksheet)
Any help is very appreciated!
Code example I am currently using to call each image click is:
Class code example that I cannot get to work is:
Userform_Initialize code example is:
I am using the date picker created by Trevor Eyre and want to use the date picker with 14 separate calendar images (Image1, Image2, etc..) to populate the date variable to the textbox adjacent to the image.
I have for now an event handler for every Image1_mousedown event that works however I hoped to utilize a class event handler that can simplify things.
The textboxes names I am populating are not in sequence from each other (1, 2, 3, etc..) they are all different numbers (textbox9, 33, 50, etc..)
Side note: I modified the date picker to show up center of the screen where workbook is displaying (multiple monitors) however would be nice it was relative to the mouse position for where it clicked the image for example just right of the image size or something. I am sure this is possible just a bit over my head at the moment.
I am hoping someone out there has a code that can be effective to capture the ImageCtrl.name and give the corresponding textbox in my case (textbox9, 33, 50, 55, etc..) the date variable.
Please note: Yes I renamed my textbox controls to Date1, Date2, etc.. for a test, and figured id need figure out a loop similar to the Userform_Initialize code below that will rename my textboxes back to their original name (textbox9, 33, 50, 55, etc..) by utilizing the textbox.tag to recall the old name as I have a loop that runs to save all my controls values to a worksheet)
Any help is very appreciated!
Code example I am currently using to call each image click is:
VBA Code:
Private Sub Image1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim dateVariable As Date
dateVariable = CalendarForm.GetDate
If dateVariable <> 0 Then TextBox9.value = dateVariable
End Sub
Class code example that I cannot get to work is:
VBA Code:
Public WithEvents ImageCtrl As MSForms.Image
Private Sub ImageCtrl_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Dim currentPage As String
'currentPage = Me.Parent.SelectedItem.Name
Dim ctrlName As String
ctrlName = Me.ImageCtrl.Name
Dim txtBoxName As String
txtBoxName = "Date" & Mid(ctrlName, 6) 'Assuming your textboxes are named Date1, Date2, etc.
'Show the date picker and set the date in the corresponding textbox
Dim dateVariable As Date
dateVariable = CalendarForm.GetDate
If dateVariable <> 0 Then
Me.Parent.Controls(txtBoxName).value = dateVariable
End Sub
Userform_Initialize code example is:
VBA Code:
Private Sub UserForm_Initialize()
For i = 1 To 14
Dim imgHandler As clsCalendarHandler
Set imgHandler.ImageCtrl = Me.Controls("Image" & i)
Next i
End Sub