Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2005

Tip: Looking for answers? Try searching our database.

Pass variables from frm1 to frm2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jasonm - 24 Sep 2005 17:48 GMT
I would like to pass variables from one user form to another in word. I have
tried various methods, but so far with no success. I know this must be able
to be done, but have started to run out of ideas. Can any one here point me
in the right direction?

I am using Word 2003.

Thanks in advance,

Jasonm
Helmut Weber - 25 Sep 2005 00:15 GMT
Hi,

if you declare a variable at module level,
there shouldn't be a problem.

At a long shot, I think, you might have been trapped
by something like this:

Module:
dim s as string
UserForm1.Show

Userform1:
Private Sub CommandButton1_Click()
s = "tralala"
UserForm2.Show
UserForm2.TextBox1.Text = s ' Textbox is empty !
End Sub

instead:

Private Sub CommandButton1_Click()
s = "tralala"
UserForm2.TextBox1.Text = s
UserForm2.Show ' Textbox contains "tralala" !
End Sub

HTH ?

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Jasonm - 25 Sep 2005 00:44 GMT
Helmut,

Thanks much for the reply. That was where I was going next, but I just
hadn't gotten there yet. I did get it to work by declaring a new instance of
frm2 and then implicitly setting the values of certain text controls on the
form from values on form 1 (I am only displaying the text to remind the user
what they did on the first page to help them through the document dreation
wizard.). I think that I may give your idea a try though as it might be a
cleaner approach which will offer more advantages besides being vilible
globally.

You wouldn't happen to know how to close one form while open the next would
you? I am using the following code:

Dim frm2 As New frmSOPPage2
   With frm2
       frm2.txtSOPNo.Value = strSOPNumber
       frm2.txtSOPTitle.Value = strSOPTitle
       frm2.txtDate = Date
   End With
   '   hide the current form
   Me.Hide     '   Hide the form
   '   this doesn't seem to be working... I still get an
   '   error when I try to close form 2
   '   show frm2
   frm2.Show

I have tried also to use unload me but nothing seems to be working I get an
error when I go to close the SECOND form that tells me that I must close the
first form! a vicious little circle.

Any assistance would be appreciated. And thank you very much for your
advice!

Jasonm
> Hi,
>
[quoted text clipped - 24 lines]
>
> HTH ?
Helmut Weber - 25 Sep 2005 01:56 GMT
Hi Jason,

a real brain twister.

Like this:

in Module1:

Sub test()
UserForm1.Show ' initializing all
End Sub

then in userform1:

Private Sub UserForm_Click()
UserForm1.Hide
UserForm2.Show
End Sub

then in userform2:

Private Sub UserForm_Click()
UserForm2.Hide
UserForm1.Show
End Sub

Don't know why I can't reference
"userformx" as "userformx" in "userformx".
Only as "userform".

Anyway, when clicking in one form, it disappears,
and the other form is shown.

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Jasonm - 25 Sep 2005 02:39 GMT
You're right! that is a brain teaser. I will give it a try and see how it
works for me.

Thanks again for all the help! I really appreciate it. I do this alot in
access, and I never seem to have these difficulties. I thought they were all
using the same VBA, but hte base program must impliment the code
differently...

Thanks again,

jasonm
> Hi Jason,
>
[quoted text clipped - 30 lines]
>
> HTH

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.