We help IT Professionals succeed at work.
Get Started

MS Excel - Set UserForm Object Variable from another UserForm

Last Modified: 2012-05-11
I'm using MS Excel 2007 UserForms to gather parameter information used with SQL stored procedures.  Each UserForm contains at least one textbox used to capture a date value.  I've been trying to make use of a single userform with a calendar control to set the various date field values found on my collection of userforms, but have not been successful at setting an object variable on the calendar userform to a reference of the calling textbox.

Within the code behind the calendar control's userform, I've created a public variable like so:
     Public dateControl As MSForms.textbox

The procedure used to set the associated textbox value is:
     Private Sub Calendar1_Click()
         dateControl.Text = Calendar1.Value

     End Sub

The code used to set the dateControl to a reference of a textbox on another userform is:
     Private Sub imgBeginDate_Click()
         Set frmCalendar.dateControl = frmEarnedHours.Controls(txtBeginDate)
     End Sub

Does anyone know how to perform this reference to a textbox on another userform, or am I going to have to create a specific calendar for each textbox which captures a date?

Watch Question
Top Expert 2008
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE