Ask the Expert

How can I access the main form's controls from the dialog box?

I have a main form and another form which acts as a dialog box. From the main form, I am calling the dialog box with the following code:

Dim DialogB As New DialogB()


This works great, but how can I access the main form's controls (i.e. frmRedem.lstBox.SelectedIndex) from the dialog box? If I use the same technique, the program will not start, and the help file's suggestion to use ParentForm does not work! I am using Windows XP.

What you're missing is that you need to use the CType function to cast the ParentForm property to access the parent. Here's an example of a function that will get the title of the parent form:
Public Sub GetParentText()
   Dim x as String
   x = CType(Me.ParentForm, Form1).Text
End Sub

This was first published in March 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: