View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Chris A[_3_] Chris A[_3_] is offline
external usenet poster
 
Posts: 11
Default Passing data back from a form

If you want to pass data from Form to Form or Sub, I have been struggling
with this one, however I muddled through. instead of making your variable
only available in the private sub define it in the declarations of the from
as a public, you can use this in any sub on that form and call it to another
from.. let me show you.

public n as long 'in userform 1 declarations

some routine that gives n it's value, such as selecting form a combobox on
the form
------------------------------

public n as long 'in userform 2 declarations

Private Sub UserForm_Activate() 'on the second form for example
n = UserForm1.n
textbox1.value = n
End Sub

the value n is now available to all subs on both forms. It all depends where
and when you need the value n. Here the value is given when the user form is
activated, it could be on the Form_click. I had a problem when i used it in
the form_initialize, the reason is that the initialize only happens once as
i used .show and .hide in my routines.

I'm not sure if this is the best way to do it but it works for me.

I think you'd be better looking into to change events for the textboxes and
giving the value over. at a guess i'd say

sub textbox1_change()
userform.textbox2.value = textbox1.value
end sub

I dare say theese guru's know a better way, wouldn't mind knowing myself
actually.

Chris A



"Neil" wrote in message
...
I have three forms in my project. Each of them have date
fields, I created a usrForm with a calender control on it
which all works fine. But how do I send the output from
the calender click event back to the correct texbox on
the correct form ?