Consulting

Results 1 to 9 of 9

Thread: how do we access a variable declared in one form to another form

  1. #1

    how do we access a variable declared in one form to another form

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Qualify it with the form name

    [vba]

    MsgBox Userform1.MyVar
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Thank you. While accessing in form 2, the same notation i used.
    value is showing 0 though the value got incremented in form 1.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    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.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    With all that detail, how could I not?

    You give me nothing to work with.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    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:
    [VBA]Public cmdClose_Click
    unload me
    End sub[/VBA]
    • FORM 2 : I am getting the data from form1 and proceeding with the rest of logic like entering num of modules and close
    [VBA]Public cmdClose_Click
    unload me
    End sub[/VBA]
    • 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.

    [VBA]Public Sub cmdenternumofmod_Click()
    OpenNumofModules_groundfixed
    End Sub[/VBA]

    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
    Last edited by nagavineela; 07-28-2010 at 10:19 PM.

  8. #8
    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:
    [VBA]Public cmdClose_Click
    unload me
    End sub[/VBA]
    • FORM 2 : I am getting the data from form1 and proceeding with the rest of logic like entering num of modules and close
    [VBA]Public cmdClose_Click
    unload me
    End sub[/VBA]
    • 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

  9. #9
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •