Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default How to set value of Textbox in loop

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default How to set value of Textbox in loop


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


"James" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default How to set value of Textbox in loop

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"

--
Rick (MVP - Excel)


"James" wrote in message
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default How to set value of Textbox in loop

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.

"James" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default How to set value of Textbox in loop

On Mar 19, 12:16*pm, JLGWhiz
wrote:
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.



"James" wrote:
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- Hide quoted text -


- Show quoted text -


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

Matt Herbert


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default How to set value of Textbox in loop

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


wrote in message
...
On Mar 19, 12:16 pm, JLGWhiz
wrote:
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.



"James" wrote:
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- Hide quoted text -


- Show quoted text -


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

Matt Herbert


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collecting textbox input within a for loop [email protected] Excel Programming 1 May 19th 06 08:01 PM
Loop Through textbox in Excel sweet Excel Programming 1 January 24th 06 04:04 PM
loop through textbox in Excel [email protected] Excel Programming 2 January 24th 06 04:01 PM
Using a DO loop to add values into a textbox Ian B Excel Programming 2 September 12th 05 07:07 PM
loop in a textbox libby Excel Programming 1 August 3rd 04 11:30 PM


All times are GMT +1. The time now is 08:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"