Ashish, Thank you for the information. 
 

_________________________________________________________________________________________________
"There are known knowns. These are things we know that we know. There are known 
unknowns. That is to say, there are things that we know we don't know. But 
there are also unknown unknowns. There are things we don't know we don't know." 




________________________________
From: Ashish Jain <26may.1...@gmail.com>
To: MS EXCEL AND VBA MACROS <excel-macros@googlegroups.com>
Sent: Sunday, 7 June, 2009 9:31:48 AM
Subject: $$Excel-Macros$$ Re: UserForm Initializing after if.. then statement


Hi Alokeshwar,

This is absolutely normal.

1. When you try to fetch the values from userform1, it is initialized
and new value of Test set upon. To avoid this you can use activate
event of userform1. Difference between activate and initialize is of
Foreground visibility active state and Background invisible initiation
state.

2. But the above solution is a mere Jugad technique. Look below to
intelligently correct your problem

Instead of using
If UserForm2.TextBox1 <> "SomeValue" And UserForm1.TextBox1 <>
"SomeValue" Then
use this
If UserForm1.TextBox1 <> "SomeValue"  AND UserForm2.TextBox1 <>
"SomeValue" Then
and then it'll display same value across both Msgbox in UserForm2.

Hope you'll understand the difference. Let me explain with example for
all excel users.
When we use boolean expression similar to this A OR B OR C. The order
of evaluation is C --> B --> A.
If C is True, then it don't evaluates A and B and the result of
expression becomes true.
But When we use boolean expression similar to this A AND B AND C. The
order of evaluation is A --> B --> C.
If A is False, then it don't evaluates C and B and the result of
expression becomes False.


If you carefully see the code and run using F8, you'll better
understand the above 2 points. Try with different expressions to
really learn this.


---------------------------------------------
Regards
Ashish Jain
http://www.excelitems.com
http://www.openexcel.com
*Developer of Open XL*
---------------------------------------------

On Jun 6, 3:11 pm, Alokeshwar Tiwary <alokeshwar.tiw...@yahoo.com>
wrote:
> Dear All,
>
> I encountered a very strange problem. I have two userforms and both of them 
> define values for few variables at Initialize event and also they both refer 
> to each other to verify certain conditions. Now what's happening is - 
> immediately after if.. then statement, the variables change .. as if the 
> other userform has been initialize. Though I have fixed this, just want to 
> know if this is normal. Please see below sample code for example:
>
> First userform has following code:
>
> Private Sub UserForm_Initialize()
> Test = "I am UserForm1"
> End Sub
>
> Second userform has following code:
>
> Private Sub UserForm_Initialize()
> Test = "I am UserForm2"
> MsgBox Test
> If UserForm2.TextBox1 <> "SomeValue" And UserForm1.TextBox1 <> "SomeValue" 
> Then
> 'Some code'
> End If
> MsgBox Test
> End Sub
>
> When I run UserForm2 where I have set value of Test to "I am UserForm2", it 
> shows msgbox "I am UserForm2" however immediately after if.. then statement 
> value of the variable Test changes and it shows msgbox "I am UserForm1" as 
> its in UserForm1. Looks like as soon as VBA reads following it changes the 
> variables:
>
> And UserForm1.TextBox1 <> "SomeValue"
>
> Do you have any idea about this?
>
> _________________________________________________________________________________________________
> "There are known knowns. These are things we know that we know. There are 
> known unknowns. That is to say, there are things that we know we don't know. 
> But there are also unknown unknowns. There are things we don't know we don't 
> know."
>
>       Explore and discover exciting holidays and getaways with Yahoo! India 
> Travelhttp://in.travel.yahoo.com/
>
>  Book1.xls
> 44KViewDownload


      Own a website.Get an unlimited package.Pay next to nothing.*Go to 
http://in.business.yahoo.com/
--~--~---------~--~----~------------~-------~--~----~
-------------------------------------------------------------------------------------
Some important links for excel users:
1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at 
http://www.excelitems.com
2. Excel tutorials at http://www.excel-macros.blogspot.com
3. Learn VBA Macros at http://www.vbamacros.blogspot.com
4. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 

To post to this group, send email to excel-macros@googlegroups.com
If you find any spam message in the group, please send an email to:
Ayush Jain  @ jainayus...@gmail.com or
Ashish Jain @ 26may.1...@gmail.com
-------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---

Reply via email to