![]() |
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 |
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 |
All times are GMT +1. The time now is 01:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com