Deafault Values of Textboxes

bong25

New Member
Joined
Jun 23, 2009
Messages
38
Hi,

I have textboxes in userform and frames, I need to set their default values but not for all of them with the same value,for example:

textbox1 to textbox15 = ""
textbox16 = "common"
textbox17 to 20 = ""
textbox21 = "standard"

Thanks in advance.
 
Hi Again I managed to make it work.

This is the code below:
Code:
Private Sub UserForm_Initialize()

Dim cCtrl As Control, cCtrlF As Control

'Loops through all Controls on UserForm Including Inside Frames
    For Each cCtrl In Me.Controls
        If TypeName(cCtrl) = "TextBox" Then
            If cCtrl.Name = "TextBox27" Then
               cCtrl.Value = "Mr. Name 01"
                   ElseIf cCtrl.Name = "TextBox28" Then
                       cCtrl.Value = "Mr. Name 02"
                           Else: cCtrl.Value = " "
                           If TypeName(cCtrl) = "Frame" Then
                               For Each cCtrlF In cCtrl.Controls
                                   If TypeName(cCtrlF) = "TextBox" Then
                                       If cCtrlF.Name = "TextBox24" Then
                                           cCtrlF.Value = "Mr. Name 03"
                                               Else: cCtrlF.Value = " "
                                       End If
                                   End If
                               Next cCtrlF
                           End If
            End If
        End If
    Next cCtrl
End Sub
Thanks for the replies guys.
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Ooops!

It's actually not fully working.

Code:
    If TypeName(cCtrl) = "Frame" Then
        For Each cCtrlF In cCtrl.Controls
            If TypeName(cCtrlF) = "TextBox" Then
                If cCtrlF.Name = "TextBox24" Then
                    cCtrlF.Value = "Mr.Name 03"
                    Else: cCtrlF.Value = " "
                End If
            End If
        Next cCtrlF
The above did not work.
 
Last edited:
Upvote 0
Ooops!

It's actually not fully working.

Code:
    If TypeName(cCtrl) = "Frame" Then
        For Each cCtrlF In cCtrl.Controls
            If TypeName(cCtrlF) = "TextBox" Then
                If cCtrlF.Name = "TextBox24" Then
                    cCtrlF.Value = "Mr.Name 03"
                    [COLOR=red]Else:[/COLOR] cCtrlF.Value = " "
                End If
            End If
        Next cCtrlF
The above did not work.


The Try changing the Else: to Else without the colon.

Not really sure, but worth a shot.
 
Upvote 0
... Try like:
Code:
[COLOR=#ff0000]Else[/COLOR]
     cCtrlF.Value = " "

In other words, remove the colon. Then press enter for a new line.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top