Results 1 to 2 of 2

Thread: Getting values from a textbox in a userform

  1. #1
    VBAX Newbie
    Joined
    Sep 2012
    Posts
    1
    Location

    Getting values from a textbox in a userform

    Hi,

    I have designed a form which has 1 textbox and 1 button.

    In one of the VBA module the userform is getting popupped. I have to get the value from text box of the userform to a variable in the module only after the user clicks the button in the userform. Till then the module code should not be executed but the userform should be displayed.

    Please help me how to get this problem solved.

    Thank you for helping me in advance

    Regards,
    Sunil TD

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    You could put this in the userform's code module
    Private Sub CommandButton1_Click()
        Me.Hide
    End Sub
    and call the userform with code like
    Sub test()
        Dim uiValue As String
        UserForm1.Show
        uiValue = UserForm1.TextBox1.Text
        Unload UserForm1
        If uiValue = vbNullString Then
            MsgBox "user entered nothing"
        Else
            MsgBox "user entered " & uiValue
        End If
    End Sub
    Last edited by Aussiebear; 07-08-2025 at 03:41 AM.

Posting Permissions

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