How to set value of Textbox in loop

J

James

Im trying to give a textbox in a userform an initial value. Its not straight
forward because the name of the textbox is not always the same (dynamic
userform). I've setup this loop but cant get oCont.Value to work. Does anyone
know why? Any Help is much appreciated. Thanks in advance

Dim oPage As Page, oCont As control

For Each oPage In DataPlate.MultiPage1.Pages
If oPage.Index >= 3 Then Exit For
For Each oCont In oPage.Controls
If TypeName(oCont) = "TextBox" Then
If InStr(1, oCont.Tag, "PD") > 0 Then
'SOMEHOW SET THE VALUE OF THE TEXTBOX HERE
ElseIf InStr(1, oCont.Tag, "Proj") > 0 Then
'SOMEHOW SET THE VALUE OF THE TEXTBOX HERE
End If
End If
Next oCont
Next oPage
 
J

JLGWhiz

If InStr(1, oCont.Tag, "PD") > 0 Then
'SOMEHOW SET THE VALUE OF THE TEXTBOX HERE
ElseIf InStr(1, oCont.Tag, "Proj") > 0 Then
'SOMEHOW SET THE VALUE OF THE TEXTBOX HERE
End If


Everything else works to this point, so if either
of the statements are true, you should be able to
use:

Me.oCont.Text = "Something" <<<'whatever your text is
 
R

Rick Rothstein

I've not worked with MultiPage before, but I would think this work. Since
your code has identified oCont as a reference to a TextBox, you should be
able to use that reference...

oCont.Text = "Assign your text variable or constant here"
 
J

JLGWhiz

P.S.

Your code either has to be in the UserForm code module, of you will have to
have the form open as non-modal with code in another module for it to work.
If you have it in another module, the Me object variable cannot be used.
 
M

meh2030

P.S.

Your code either has to be in the UserForm code module, of you will have to
have the form open as non-modal with code in another module for it to work.  
If you have it in another module, the Me object variable cannot be used.







- Show quoted text -

Did you try oCont.Value = "your value here"?

Matt Herbert
 
J

JLGWhiz

Hi Matt, in a textbox, Value and Text are interchangeable.


P.S.

Your code either has to be in the UserForm code module, of you will have
to
have the form open as non-modal with code in another module for it to
work.
If you have it in another module, the Me object variable cannot be used.







- Show quoted text -

Did you try oCont.Value = "your value here"?

Matt Herbert
 

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