Accessing Form1 control values from Form2

C

cmonroe21

I have two forms, both with text boxes, labels and command buttons on them.
I need to be able to click the command button on Form2 and access the control
values in Form1 and place them into the controls on Form2. I just don't know
how to access a second form from the first one. Pretty basic, I know! If
you have any input, please let me know!
 
K

Ken Slovak - [MVP - Outlook]

You cannot click a button in a form using code since the
MSForms.CommandButton control doesn't expose a Click or Execute or
equivalent method.

To get to another open item you iterate the Inspectors collection. Every
open item is in that collection. To identify the item you can check the
MessageClass, Subject or other property that you know will be unique.

Once you have the item's Inspector you use its ModifiedFormPages collection
to get the page (tab) and then use the page's Controls collection to access
specific controls:

' oInsp is the Inspector
Set oPage = oInsp.ModifiedFormPages.Item("myFormPageName")
Set oTextBox1 = oPage.Controls.Item("TextBox1Name")
 
C

cmonroe21 via OfficeKB.com

Thanks so much! I was sort of using this convention by:

Set objPage = Item.GetInspector.ModifiedFormPages("Message")
Set objControl = objPage.Controls("TextBox1")
MyValue - objControl.Value

But for some reason it wasn't working :( I've decided to scratch the Outlook
script editor and opt to use Vba in VB editor. Instead of messing with
swapping between the Message and P.2 tabs, and the compose and read messages,
I just created a form with the controls to inquire the data I need, then a
button that sends a newly created email item that contains the data.

Thanks so much for your help... the iterating between Inspectors is a new
concept for me. You would just create a loop to check the specific property
of each iteration? Veddy Inteddesting....
You cannot click a button in a form using code since the
MSForms.CommandButton control doesn't expose a Click or Execute or
equivalent method.

To get to another open item you iterate the Inspectors collection. Every
open item is in that collection. To identify the item you can check the
MessageClass, Subject or other property that you know will be unique.

Once you have the item's Inspector you use its ModifiedFormPages collection
to get the page (tab) and then use the page's Controls collection to access
specific controls:

' oInsp is the Inspector
Set oPage = oInsp.ModifiedFormPages.Item("myFormPageName")
Set oTextBox1 = oPage.Controls.Item("TextBox1Name")
I have two forms, both with text boxes, labels and command buttons on them.
I need to be able to click the command button on Form2 and access the
[quoted text clipped - 3 lines]
how to access a second form from the first one. Pretty basic, I know! If
you have any input, please let me know!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top