+ Reply to Thread
Results 1 to 2 of 2

Newbie TextBox problem - Please help.

  1. #1
    krayten
    Guest

    Newbie TextBox problem - Please help.

    Please help me to work this out!!

    The code below is from my UserForm3 which is a simple form with
    three textboxes, from which I need to gather some variables _for later
    use_.

    I am testing with gathering the variables ( hostname, UserID and pass )
    then
    I want to show message boxes showing their values ( on submit - at the
    top ).

    I'm a real newbie to xlvba and would really appreciate some help
    regarding how to
    get the values of a textbox "out" of it's own textbox change sub.

    Thanks in advance!

    Stuart


    ' On Submit
    Sub CommandButton2_Click()
    MsgBox hostname
    MsgBox UserID
    MsgBox pass

    End Sub



    ' Cancel and clear
    Sub CommandButton3_Click()
    Unload UserForm3
    UserForm3.Hide

    End Sub

    ' Enter the hostname
    Sub TextBox1_Change()
    Dim hostname As String
    hostname = TextBox1.Text

    End Sub

    ' Enter the user id
    Sub TextBox2_Change()
    Dim UserID As String
    UserID = TextBox2.Text

    End Sub

    ' Enter the password
    Sub TextBox3_Change()
    Dim pass As String
    pass = TextBox3.Text


    End Sub

    Private Sub UserForm_Click()

    End Sub


  2. #2
    Dave Peterson
    Guest

    Re: Newbie TextBox problem - Please help.

    This goes in a general module--not behind the userform:

    Option Explicit
    Public HostName As String
    Public UserID As String
    Public Pass As String
    Sub showTheForm()
    UserForm1.Show
    MsgBox HostName & vbLf & UserID & vbLf & Pass
    End Sub

    This goes behind the userform:

    Option Explicit
    Sub CommandButton3_Click()
    HostName = Me.TextBox1.Text
    UserID = Me.TextBox2.Text
    Pass = Me.TextBox3.Text
    Unload Me
    End Sub

    The variables are declared public, so they're visible to all the procedures.
    (Check out scope and visibility in VBA's help.)

    The me. stuff refers to the thing that owns the code. In this case it's the
    userform.

    You'll want to add some validation, too (I would suspect).

    krayten wrote:
    >
    > Please help me to work this out!!
    >
    > The code below is from my UserForm3 which is a simple form with
    > three textboxes, from which I need to gather some variables _for later
    > use_.
    >
    > I am testing with gathering the variables ( hostname, UserID and pass )
    > then
    > I want to show message boxes showing their values ( on submit - at the
    > top ).
    >
    > I'm a real newbie to xlvba and would really appreciate some help
    > regarding how to
    > get the values of a textbox "out" of it's own textbox change sub.
    >
    > Thanks in advance!
    >
    > Stuart
    >
    > ' On Submit
    > Sub CommandButton2_Click()
    > MsgBox hostname
    > MsgBox UserID
    > MsgBox pass
    >
    > End Sub
    >
    > ' Cancel and clear
    > Sub CommandButton3_Click()
    > Unload UserForm3
    > UserForm3.Hide
    >
    > End Sub
    >
    > ' Enter the hostname
    > Sub TextBox1_Change()
    > Dim hostname As String
    > hostname = TextBox1.Text
    >
    > End Sub
    >
    > ' Enter the user id
    > Sub TextBox2_Change()
    > Dim UserID As String
    > UserID = TextBox2.Text
    >
    > End Sub
    >
    > ' Enter the password
    > Sub TextBox3_Change()
    > Dim pass As String
    > pass = TextBox3.Text
    >
    > End Sub
    >
    > Private Sub UserForm_Click()
    >
    > End Sub


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1