TextBox Text

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • if1467
    New Member
    • Feb 2008
    • 25

    TextBox Text

    I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by if1467
    I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
    What are you working with? VBA built into Excel? Which version?

    The textbox's .Text property is most likely what you want to change.

    As for where to place the code, I'd guess the form's Activate, Layout or Initialize event procedure.

    Comment

    • kadghar
      Recognized Expert Top Contributor
      • Apr 2007
      • 1302

      #3
      Originally posted by if1467
      I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
      Yeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:

      [CODE=vb]Textbox1.text= worksheets("she et1").cells(5,1 ).value 'This is for cell A5[/CODE]

      HTH

      Comment

      • if1467
        New Member
        • Feb 2008
        • 25

        #4
        Originally posted by kadghar
        Yeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:

        [CODE=vb]Textbox1.text= worksheets("she et1").cells(5,1 ).value 'This is for cell A5[/CODE]

        HTH
        I am very new to using forms, so I am going to need some more help.

        Right now I have a form with 3 options. The "OK" command code is:

        Code:
        Private Sub CommandButton1_Click()
        Unload Me
        If ListBox1.ListIndex = -1 Then
            MsgBox "No item selected", vbExclamation
            Exit Sub
        End If
        Range("G4") = ListBox1.ListIndex + 1
        If Range("G4") = "1" Then
        Purchase_Action.Show
        End If
        If Range("G4") = "2" Then
        Sale_Action.Show
        End If
        If Range("G4") = "3" Then
        Coupon.Show
        End If
        Unload Me
        End Sub
        The form that I need a textbox filled is on the "Coupon" form.

        I am not sure what is meant by the inititialize event, and where to place the code for the text.

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          To find the event procedures, double-click on the userform in the editor. This should bring up the code window for the userform. You can use the two pulldown listboxes at the top of the window to select the form or a control, and the various events that pertain to them.

          Comment

          • if1467
            New Member
            • Feb 2008
            • 25

            #6
            Originally posted by Killer42
            To find the event procedures, double-click on the userform in the editor. This should bring up the code window for the userform. You can use the two pulldown listboxes at the top of the window to select the form or a control, and the various events that pertain to them.
            Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?

            Comment

            • kadghar
              Recognized Expert Top Contributor
              • Apr 2007
              • 1302

              #7
              Originally posted by if1467
              Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?
              [CODE=vb]TextBox1.Font.N ame = Cells(1, 1).Font.Name
              TextBox1.Font.S ize = Cells(1, 1).Font.Size[/CODE]

              or

              [CODE=vb]TextBox1.Font.N ame = Range("A4").Fon t.Name
              TextBox1.Font.S ize = Range("A4").Fon t.Size[/CODE]

              and the same for each font's property you want to copy

              Comment

              • if1467
                New Member
                • Feb 2008
                • 25

                #8
                Originally posted by kadghar
                [CODE=vb]TextBox1.Font.N ame = Cells(1, 1).Font.Name
                TextBox1.Font.S ize = Cells(1, 1).Font.Size[/CODE]

                or

                [CODE=vb]TextBox1.Font.N ame = Range("A4").Fon t.Name
                TextBox1.Font.S ize = Range("A4").Fon t.Size[/CODE]

                and the same for each font's property you want to copy
                I guess I should have been morespecific if I wanted a more specific answer. The text that I am putting in the textbox is supposed to be a percentage like 10.25%, but the box is showing 0.1025. How do I format the text for this criteria?

                Comment

                • kadghar
                  Recognized Expert Top Contributor
                  • Apr 2007
                  • 1302

                  #9
                  Originally posted by if1467
                  I guess I should have been morespecific if I wanted a more specific answer. The text that I am putting in the textbox is supposed to be a percentage like 10.25%, but the box is showing 0.1025. How do I format the text for this criteria?
                  That might be a little bit more complex, since the cells have the NumberFormat property, that textboxes dont have... but assuming the Format function have the same parameters as the Excel's property, something like this should do:

                  [CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]

                  If that doesn't work, i think we'll have to make a HomeMade function for this purpose.

                  Comment

                  • if1467
                    New Member
                    • Feb 2008
                    • 25

                    #10
                    Originally posted by kadghar
                    That might be a little bit more complex, since the cells have the NumberFormat property, that textboxes dont have... but assuming the Format function have the same parameters as the Excel's property, something like this should do:

                    [CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]

                    If that doesn't work, i think we'll have to make a HomeMade function for this purpose.
                    Thanks for the tip.

                    I tried

                    [CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]

                    and it returned "Ge1eral"
                    so I tried

                    [CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Worksheets("Rev iewer Back-Up").Cells(2, 6).NumberFormat )[/CODE]

                    and it worked!!

                    Comment

                    Working...