Passing variables between user forms

M

M.P. Frosch

I am writting a VBA set of forms with Word XP. I have designed a series of
questions that are answered with check boxes. For some of these answers,
there is a need to additional information. I designed another form
(usrAdditional_Info) which has a single text field
(txtAdditionalInformation) as well as Cancel, Clear and Enter buttons.

I am stuck at figuring out how to have the text entered in
usrAdditional_Info back to the other form.

Here are the relevant bits of coding:

From the starting data form:
Private Sub cbxScalpLaceration_Click()
'
' Get additional information if laceration present
'
If cbxScalpLaceration.Value = True Then
Load usrAdditional_Info
usrAdditional_Info.Show
'THIS IS WHERE I WANT TO GET THE ADDITIONAL INFORMATION TEXT
End If
End Sub

From usrAdditional_Info:

Sub cmdCancel_Click()
txtAdditionalInformation.Value = Null
Unload usrAdditional_Info
End Sub

Sub cmdClear_Click()
txtAdditionalInformation.Value = Null
End Sub

Sub cmdSave_Click()
Unload usrAdditional_Info
End Sub


TIA.

Matthew Frosc
 
P

Perry

If userforms are loaded, you can exchange values forthwith like
in below example:

f1.txtText = f2.txtOther

whereby: f1 is an object variable pointing to a (loaded) userform
and f2 the object variable pointing to another (loaded) userform
txtText is a TextBox on f1, and txtOther is a TextBox in f2

Krgrds,
Perry
 
M

M.P. Frosch

Thanks for the suggestion, but your reply is so cryptic that I can't figure
out exactly how to follow the suggestion. Where do I defined the object
variables? How do I "point them" at a userform? A bit more assitance for a
beginner please.

Thanks.
 
H

Henry

Matthew,

On your opening userform called, say,Opening_Frm put a textbox called, say,
txt99.
You can hide it if you wish.

In Form usrAdditional_Info

Sub cmdSave_Click()
Opening_Frm.txt99.Text = txtAdditionalInformation.Text
Unload usrAdditional_Info
End Sub

When you unload usrAdditional_Info the text will still be available in
txt99.

HTH
Henry
 

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