LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default How to get get variables to move from userform to main sub?

I just tried that and watched the value of LocID and it keeps the value

until the UNLOAD USERFORM1 command is ran and then I get 'out of
context' for that variable even with the public declaration of the
variables. See my code below. (It's very simple.) .. Thx!


Public Direction As String
Public DOW As String
Public LocID As String
Private Sub CommandButton2_Click()


End Sub
Private Sub OKButton_Click_Click()
Msg = "You selected Item # "
Msg = Msg & ListBox1.ListIndex
Msg = Msg & vbCrLf
Msg = Msg & ListBox1.Value
LocID = ListBox1.Value
MsgBox Msg
Unload UserForm1
End Sub
Private Sub UserForm_Click()


End Sub


//////////////////////////////REPLY I GOT WAS
THIS//////////////////////////////////////////////


From: K Dales - view profile
Date: Wed, May 10 2006 11:45 am
Email: K Dales
Groups: microsoft.public.excel.programming
Not yet ratedRating:
show options


Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author


If you declare all your variables used for input as Public (at the top
of the
userform module - not inside your subs) they are global variables; that

is,
they are available to all modules. There are other ways, too, but this

is
simplest.
--
- K Dales


- Hide quoted text -
- Show quoted text -




- Hide quoted text -
- Show quoted text -

"Chet" wrote:
Hi -
I am new to using 'custom dialog boxes'. I am trying to take some data
from my user form once I have hit the OK button on the userform and
bring those entries back to my main sub where I will use this data to
run the rest of my code. I am able to get the form working but the
userform inputs seem to be local to the code that I have for the form
but I haven't been able to get the variables back to my main code
section.
PS, My userform is in my personal.xls and I will be using the data to
affect a separate workbook.
Thanks,
Chet
Code I have so far....
'///////////////////////CODE IN THE
USERFORM///////////////////////////////////////
Private Sub CommandButton2_Click()
End Sub
Private Sub OKButton_Click_Click()
Msg = "You selected Item # "
Msg = Msg & ListBox1.ListIndex
Msg = Msg & vbCrLf
Msg = Msg & ListBox1.Value
LocID = ListBox1.Value
MsgBox Msg
Unload UserForm1
End Sub
'/////////////////MAIN PROGRAM CODE////////////////////////////////
Sub TOOLBAR_POSTAL_BYP_MIX_BREAKOUT_vsn2()
With UserForm1.ListBox1
.AddItem "SFO"
.AddItem "OAK"
.AddItem "SJC"
End With
With UserForm1.ListBox2
.AddItem "ORIG"
.AddItem "DEST"
End With
With UserForm1.ListBox3
.AddItem "Weekday"
.AddItem "Saturday"
.AddItem "Sunday"
End With
UserForm1.ListBox1.ListIndex = 0
UserForm1.Show
'the rest of the code follows here unrelated to the data / form
entry//////////
Application.ScreenUpdating = False
Direction = InputBox("Input DEST or ORIG")
Direction = UCase(Direction)



//////////////////////////////////////ORIGINAL POSTING
/////////////////////////////////////
Hi -
I am new to using 'custom dialog boxes'. I am trying to take some data


from my user form once I have hit the OK button on the userform and
bring those entries back to my main sub where I will use this data to
run the rest of my code. I am able to get the form working but the
userform inputs seem to be local to the code that I have for the form
but I haven't been able to get the variables back to my main code
section.


PS, My userform is in my personal.xls and I will be using the data to
affect a separate workbook.


Thanks,
Chet


Code I have so far....


'///////////////////////CODE IN THE
USERFORM///////////////////////////////////////
Private Sub CommandButton2_Click()


End Sub


Private Sub OKButton_Click_Click()
Msg = "You selected Item # "
Msg = Msg & ListBox1.ListIndex
Msg = Msg & vbCrLf
Msg = Msg & ListBox1.Value
LocID = ListBox1.Value
MsgBox Msg
Unload UserForm1
End Sub


'/////////////////MAIN PROGRAM CODE////////////////////////////////
Sub TOOLBAR_POSTAL_BYP_MIX_BREAKOUT_vsn2()


With UserForm1.ListBox1
.AddItem "SFO"
.AddItem "OAK"
.AddItem "SJC"
End With
With UserForm1.ListBox2
.AddItem "ORIG"
.AddItem "DEST"
End With
With UserForm1.ListBox3
.AddItem "Weekday"
.AddItem "Saturday"
.AddItem "Sunday"
End With


UserForm1.ListBox1.ListIndex = 0
UserForm1.Show


'the rest of the code follows here unrelated to the data / form
entry//////////
Application.ScreenUpdating = False
Direction = InputBox("Input DEST or ORIG")
Direction = UCase(Direction)

 
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 and variables Jeff Excel Discussion (Misc queries) 1 May 24th 06 02:20 PM
adding a worksheet causes main userform to corrupt Magius00 Excel Programming 4 October 26th 05 09:02 AM
Userform.Lable Variables Roger Excel Programming 6 October 9th 05 10:27 PM
Passing variables between Sub and Userform jose luis Excel Programming 8 July 22nd 05 05:20 PM
Access from add_in userform to main template userform.... Ajit Excel Programming 1 November 18th 04 05:15 PM


All times are GMT +1. The time now is 08:50 AM.

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

About Us

"It's about Microsoft Excel"