PC Review


Reply
Thread Tools Rate Thread

Displaying different worksheets based on user input

 
 
David
Guest
Posts: n/a
 
      25th Sep 2007
I've the following code in a User Form:

------

Private Sub OptionButton1_Click()
sScreen = "Purchase"
End Sub

Private Sub OptionButton2_Click()
sScreen = "Remortgage"
End Sub

Private Sub CommandButton2_Click()
'' They've clicked proceed, which screen do we open next?
If (sScreen = "Remortgage") Then
Sheets("Sheet2").Activate
Else
Sheets("Sheet3").Activate
End If
Unload UserForm1
End Sub

----

It always displays "Sheet3" after the "proceed" button is pressed,
regardless of which radio button the user selects, I assume the
variable sScreen isn't being carried over into the final Private Sub,
what do I need to do to ensure it is?

Or is there another problem here?

Excel 97.
Thanks for any help!

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      25th Sep 2007
David,

Declare the variable

Public sscreen As String

Select General|Declarations
and paste it in there.

Mike

"David" wrote:

> I've the following code in a User Form:
>
> ------
>
> Private Sub OptionButton1_Click()
> sScreen = "Purchase"
> End Sub
>
> Private Sub OptionButton2_Click()
> sScreen = "Remortgage"
> End Sub
>
> Private Sub CommandButton2_Click()
> '' They've clicked proceed, which screen do we open next?
> If (sScreen = "Remortgage") Then
> Sheets("Sheet2").Activate
> Else
> Sheets("Sheet3").Activate
> End If
> Unload UserForm1
> End Sub
>
> ----
>
> It always displays "Sheet3" after the "proceed" button is pressed,
> regardless of which radio button the user selects, I assume the
> variable sScreen isn't being carried over into the final Private Sub,
> what do I need to do to ensure it is?
>
> Or is there another problem here?
>
> Excel 97.
> Thanks for any help!
>
>

 
Reply With Quote
 
JW
Guest
Posts: n/a
 
      25th Sep 2007
You are sharing variables across the userform, so you to declare the
variable as a Public Variable. At the top of your userform subs,
place:
Public sScreen As String

That should fix ya up.

David wrote:
> I've the following code in a User Form:
>
> ------
>
> Private Sub OptionButton1_Click()
> sScreen = "Purchase"
> End Sub
>
> Private Sub OptionButton2_Click()
> sScreen = "Remortgage"
> End Sub
>
> Private Sub CommandButton2_Click()
> '' They've clicked proceed, which screen do we open next?
> If (sScreen = "Remortgage") Then
> Sheets("Sheet2").Activate
> Else
> Sheets("Sheet3").Activate
> End If
> Unload UserForm1
> End Sub
>
> ----
>
> It always displays "Sheet3" after the "proceed" button is pressed,
> regardless of which radio button the user selects, I assume the
> variable sScreen isn't being carried over into the final Private Sub,
> what do I need to do to ensure it is?
>
> Or is there another problem here?
>
> Excel 97.
> Thanks for any help!


 
Reply With Quote
 
David
Guest
Posts: n/a
 
      25th Sep 2007
Thanks both, now working!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying input fields based on a combo box selection ace Microsoft Access Form Coding 5 4th Jun 2009 07:44 AM
displaying input data on user form as currency mantrid Microsoft Excel Programming 2 28th Apr 2007 01:56 AM
Displaying a user input entry on a report =?Utf-8?B?RXJuaWUgU2Vyc2Vu?= Microsoft Access Reports 0 23rd Aug 2006 09:31 PM
Displaying cell contents based on input? =?Utf-8?B?Rmxlb25l?= Microsoft Excel Programming 7 2nd Feb 2005 12:09 AM
CODE to select range based on User Input or Value of Input Field Sandi Gauthier Microsoft Excel Programming 4 8th Dec 2003 03:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:22 AM.