Userform Help
Hi guys i am having a lot of dificulty with userforms. I have been trying for so long and nothing is working. I have userform that has three textboxes and a submit button. I want the use to put in certain values in the boxes, press submit and those values b submitted into three different variable. Can anyone help with this -- jnasr0 ----------------------------------------------------------------------- jnasr00's Profile: http://www.excelforum.com/member.php...fo&userid=2851 View this thread: http://www.excelforum.com/showthread.php?threadid=48337 |
Userform Help
How you do this would depend on what you intend doing with those
variables. If you wanted to use them immediatley in another macro then you could do it like this: In the form module: Private Sub CommandButton1_Click() Dim Var1 As String Dim Var2 As String Dim Var3 As String Var1 = Me.TextBox1.Text Var2 = Me.TextBox2.Text Var3 = Me.TextBox3.Text Call other(Var1, Var2, Var3) Unload Me End Sub In a normal module: Sub other(str1 As String, str2 As String, str3 As String) MsgBox "The values a " & Chr(10) & str1 & _ Chr(10) & str2 & Chr(10) & str3 End Sub If you wanted these values to be available to a procedure that will be called at some point later in the same session then you need to declare the global public variables. This must be done in a standard module at the top in the declarations section eg: Option Explicit Public Var1 As String Public Var2 As String Public Var3 As String Your form code would then be: Private Sub CommandButton1_Click() Var1 = Me.TextBox1.Text Var2 = Me.TextBox2.Text Var3 = Me.TextBox3.Text Unload Me End Sub and later in a seperate macro you could refer to the variables like this: Sub getvals() MsgBox "The values a " & Chr(10) & Var1 & _ Chr(10) & Var2 & Chr(10) & Var3 End Sub Finally if you want the values to be available after closing and opening the book then you should save the values to cells on a worksheet (possibly hidden) and then reference those cells later eg: Private Sub CommandButton1_Click() With Sheets("FormData") Range("A1").Value = Me.TextBox1.Text Range("A2").Value = Me.TextBox2.Text Range("A3").Value = Me.TextBox3.Text End With Unload Me End Sub Hope this helps Rowan jnasr00 wrote: Hi guys i am having a lot of dificulty with userforms. I have been trying for so long and nothing is working. I have a userform that has three textboxes and a submit button. I want the user to put in certain values in the boxes, press submit and those values be submitted into three different variable. Can anyone help with this? |
All times are GMT +1. The time now is 08:01 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com