PDA

View Full Version : how do we access a variable declared in one form to another form



nagavineela
07-28-2010, 07:06 AM
Hi,
I have declared a variable as Public pmsel as integer in form 1 and am trying to access the value in form 2 but am unable to access. Pls help me in resolving this.

Bob Phillips
07-28-2010, 07:09 AM
Qualify it with the form name



MsgBox Userform1.MyVar

nagavineela
07-28-2010, 07:12 AM
Thank you. While accessing in form 2, the same notation i used.
value is showing 0 though the value got incremented in form 1.

Bob Phillips
07-28-2010, 07:26 AM
Did you unload the first form? If so, all memory is cleraed down, and it will re-initialize next time. Don't unload, hide it.

nagavineela
07-28-2010, 10:00 AM
Hi,
Thanks a lot. "Me.Hide" helped me a lot. I am now facing one more problem. I have 3 active x buttons in my excel assigned with macro each.
i click on first and enter values. when i click on second button, loading of data into other form is taking too much of time. Please help me.

Bob Phillips
07-28-2010, 10:03 AM
With all that detail, how could I not?

You give me nothing to work with.

nagavineela
07-28-2010, 10:25 AM
Am sorry.
Hi,
I have created 5 userforms as listed below:
1) Nameofmod
2) Numofmod
3) Update
4) Calculate
5) Append.

I have 5 Active X buttons on the excel with above forms as macros assigned to it

Steps followed:

I enter all details in the first form and close.
Code for close button is as follows:
Public cmdClose_Click
unload me
End sub
FORM 2 : I am getting the data from form1 and proceeding with the rest of logic like entering num of modules and closePublic cmdClose_Click
unload me
End sub
Form 4: i am getting the data from form 2 and proceeding with the logic and close the form.When i click on the buttons in the sequence said above, i am unable to retrieve data from form 2 to form 4.

Tried using "Me.Hide" instead of "Unload Me".
When i do this form2 and form4 is holding previous data rather than picking up the latest.

Each button has been assigned macro.

for all buttons, macro's are assigned in sheet1.

MAcro is assigned as follows for button.

Public Sub cmdenternumofmod_Click()
OpenNumofModules_groundfixed
End Sub

How do we handle this case? Do we have any option of saving form's data prior to unloading.
Please help me.

Thanks

Please let me know what else i need to furnish.



Thank you very much

nagavineela
07-28-2010, 10:18 PM
Hi,
I have created 5 userforms as listed below:
1) Nameofmod
2) Numofmod
3) Update
4) Calculate
5) Append.

I have 5 Active X buttons on the excel with above forms as macros assigned to it

Steps followed:

I enter all details in the first form and close.
Code for close button is as follows:
Public cmdClose_Click
unload me
End sub
FORM 2 : I am getting the data from form1 and proceeding with the rest of logic like entering num of modules and closePublic cmdClose_Click
unload me
End sub
Form 4: i am getting the data from form 2 and proceeding with the logic and close the form.When i click on the buttons in the sequence said above, i am unable to retrieve data from form 2 to form 4.

Tried using "Me.Hide" instead of "Unload Me".
When i do this form2 and form4 is holding previous data rather than picking up the latest.

How do we handle this case? Do we have any option of saving form's data prior to unloading.
Please help me.

Thanks

nagavineela
07-29-2010, 01:17 AM
Hi,
I have a combo box
with cbomodulename
.Additem A
.Additem B
.Additem C
.Additem D
.Additem E
end with

I have selected only A and D items in excel. How do i append rest of the items in my excel. Please help me