Referencing a U-Form control from another U-Form/Class, via variable

ClimoC

Well-known Member
Joined
Aug 21, 2009
Messages
584
Guten Tag

As a work around to the loss of the Calendar-Control in 2010, I've sourced (googled) a class 'Calendar' with a nifty wee Userform (anyone who can help with this will be aware of such things)

So I have several non-modal userforms in my App, some of them have date-fields that require manual entry typing of dd/mm/yy etc (No single userform has more than one date-box in it, this I think may be pivotally helpful)

Now the Userform 'Calendar' that is built on the class of the same (cCalendar) name, has the write value line 'ActiveCell.value = theCal.value'

I'm looking to change this to refer to the correct userform.Textbox value, depending on which form is open.

I would imagine I could simply have a global string, whose value is set (or re-set) whenever a Userform is initialized (some sort of 'ActiveUF.value = Me.Name), where I get lost is referring to the components by name, so as to have a case statement by where I go:

Code:
Private Sub theCal_AfterUpdate()

Select Case ActiveUF
           Case "AddForm"
                  application.vbe.components("AddForm").controls("AddFormDatePicker").value = theCal.value
           Case "EditForm"
           '.... etc
end select
end sub

Can anyone suggest a better way of doing this (instead of passing around the userform name as a variable) - or advise the proper syntax for referring to controls outside of the 'active' userform (but an open userform nonetheless) please?

Every time I have to do this particular thing with userforms, I completely forget how, and the object browser always leads me on an infinite loop of
Application.vbe.activevbproject.vbcomponents.vbe.active....

Thanks
C

PS - there may be one slight complication to the process - one of the forms, has a 2-tab page in it, each page having similar (but named differently) fields. So I may need to be able to throw in 'Activepage' or whatnot
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Oh jesus. I can't believe it's that simple.

If it's called "AddForm"... the line is

Code:
AddForm.DateField.value =

Slow day. Not enough sleep

Sorry to bother people unecessarily!
 
Upvote 0
I would add a textbox variable to the calendar form and have it populate that instead of activecell. you then simply assign the relevant control when calling the calendar form from any other form.
 
Upvote 0
I would add a textbox variable to the calendar form and have it populate that instead of activecell. you then simply assign the relevant control when calling the calendar form from any other form.

As usual Rory, your solution would be far more elegant. As I figured out that there are in fact 3 forms with 2'date'textboxes, what I've done is pass a global string variable to the Calendar form, which using a caseStatement, writes to the appropriate field
 
Upvote 0
each to their own. :)
 
Upvote 0
I wrote my own calendar form and I have there a function (getCal) that loads calendar form and user selected date is returned.

activecell.value = getCal
me.textbox1.value = getCal
etc....
 
Upvote 0

Forum statistics

Threads
1,216,072
Messages
6,128,631
Members
449,460
Latest member
jgharbawi

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