Load Calendar on Textbox enter

Jimmypop

Well-known Member
Joined
Sep 12, 2013
Messages
753
Office Version
  1. 365
Platform
  1. Windows
Good day all

I have a subroutine called AdvancedCalendar.

I need to run this sub everytime a user enters a text box which has a tag "date"

code below not working

VBA Code:
Private Sub UserForm_Initialize()


    Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is TextBox Then
            If ctl.Tag = "date" Then
 Call AdvancedCalendar
            End If
        End If
    Next ctl

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi
try qualifying the TextBox object with the Microsoft Object Library & see if this resolves your issue

Rich (BB code):
If TypeOf ctl Is msforms.TextBox Then

Dave
 
Upvote 0
Hi Dave

This does now bring up the Calendar form... however it does this on userform initialize for every textbox and then only show the userform... it needs to only on entering the textbox with tag date
 
Upvote 0
Hi Dave

This does now bring up the Calendar form
This I take it suggestion resolved the posted issue?

however it does this on userform initialize for every textbox and then only show the userform... it needs to only on entering the textbox with tag date

This is a slightly different issue & post not fully clear to me

If you only need need to call the the code AdvancedCalendar once then place and Exit For statement after the Call line

Rich (BB code):
            If ctl.Tag = "date" Then
                Call AdvancedCalendar
                Exit For
            End If

Dave
 
Upvote 0
Sorry for not being clear...

I have a userform with about 88 textboxes which have a tag "date". No I want to run the AdvancedCalendar sub whenever one enters the textbox with relevant tag. code at the moment does show the calendar... however it is showing it 88 times and then only opens up the userform
 
Upvote 0
Maybe the Enter Event of the control will do what you want

VBA Code:
Private Sub TextBox1_Enter()
         If Me.TextBox1.Tag = "date" Then Call AdvancedCalendar
End Sub

Dave
 
Upvote 0
It does work yes... Now will just investigate on what to do to het it to work for the other 87 textboxes🙈🙈dont want to write that for all of them... Will see maybe if there is a way to do with a class module or similar
 
Upvote 0
Glad suggestion helps & a class would be a sensible approach but off top of my head, I don't think the Enter Event is available.

Dave
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,119
Members
452,381
Latest member
Nova88

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