Text box values in user forms

J

Joanne

I'm sorry to appear to thick, but how do I transfer the value of a text box
that is in a user form to a routine that is in another procedure? I keep
getting an error that the variable is not set but it is!

Thanks very much.
 
D

Dawn Crosier

Dim strString as String
strString = UserForm1.textbox1.Value

'Send value to Function
OpenTemplate(strString)

'Function receives value in the byVal arrTemplates
Function OpenTemplate(ByVal arrTemplates) As Variant
.....more code to

Does that help? If not, please post what you have so I can make the
example more like what you are doing.

--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
 
J

Joanne

Hello,
Here are the two routines, one is straight from a book I have that I would
like to modify if I could only get it to work. The message box keeps
erroring out and saying that there is no variable declared.

Thank you very much for your help.
_______________________________________
Option Explicit
Dim rng As Range
Dim sText As String

Sub StartSig()
frmSignature.Show
End Sub

Sub ChooseSig()

MsgBox sTextFill
End Sub



(This is the user form)
Public sTextFill As String
Option Explicit

Sub cmdAddSig_Click()
Me.Hide
Dim stSigText As String
sTextFill = Me.txtName.Text
Signature.ChooseSig
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub
 
D

Dawn Crosier

Try changing your code to:

Option Explicit
Dim rng As Range
Dim sText As String

Sub StartSig()
frmSignature.Show
End Sub

Sub ChooseSig(sTextFill As String)

MsgBox sTextFill
End Sub



'(This is the user form)
Public sTextFill As String
Option Explicit

Sub cmdAddSig_Click()
Me.Hide
Dim stSigText As String
sTextFill = Me.txtName.Text
ChooseSig (sTextFill)
End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub


I think you have a lot of items declared that you don't need, but then
you may not be showing me all of the code either. <smile>

Here is a very nice article on debugging techniques which will assist
you in following the values of your variables as they float through
your code.
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=410

Let me know how it goes.

--
Dawn Crosier
Microsoft MVP
"Education Lasts a Lifetime"

This message is posted to a newsgroup. Please post replies and
questions to the newsgroup so that others can learn as well.
 
J

Joanne

Thank you so much for your help. I tried your code but unfortunately it
still says "Variable not defined" when I try to run it. I just don't get it.
I will try to use those good debugging tips in the article you recommended.
If you can think of anything else I'd so appreciate it.
 

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