Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform from a Userform Problem Adrian Excel Programming 1 October 12th 05 04:57 PM
Looping procedure calls userform; how to exit loop (via userform button)? KR Excel Programming 6 July 27th 05 12:57 PM
Activating userform and filling it with data form row where userform is activate Marthijn Beusekom via OfficeKB.com[_2_] Excel Programming 3 May 6th 05 05:44 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM
Linking userform to userform in Excel 2003 missmelis01 Excel Programming 2 August 27th 04 08:07 PM


All times are GMT +1. The time now is 01:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"