Passing Variables to Multiple Forms

I have searched for and read several responses to questions and I'm still coming up a little hazy on this.  Here's the deal.  I have a project in which I will have employees updating people's records.  Imagine a list of names that can be double-clicked.  When a name on a list is double-clicked, it displays another form that shows everyone's name, address, etc -- all data we have on that person.  Now from there, I have a third form that can be activated by someone checking on a checkbox control.  When this checkbox is clicked, I want to display a third form that will have some of the variables from the FIRST form.

I can't make these values global or public because someone may have several records open at one time, and may hop from one record to the next and may not update the records in the order they were accessed.  Therefore, I need to create distinct "copies" of this variable available on the third form, and they will always have to come from their own "parent".

This is an example of how the variables would be used:

Open MainForm

Double-click Name #1, create DetailForm #1

Go back to Mainform, double-click Name #2, Create DetailForm #2

Go back to DetailForm #1, click the checkbox, display some of the variables from DetailForm #1

Go back to DetailForm #2, click the checkbox, display some of the varables from DetailForm #2

etc

Somehow I need to make sure all the "children" variables are kept with their proper "parent" variables, if that's the terminology I need to use.  I'm not asking you to write the code for me (although examples are always appreciated)!  It would be much better if you could explain the concept of what I need to do so I can learn it myself  ... I'd appreciate it very much.





UPRRDevelopersAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
You could simply have Public variables on the 'child' form.

Dim frm As New DetailedForm
frm.strParentName = "Selected Name on Mainform"
frm.Visible = True
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UPRRDevelopersAuthor Commented:
Here's what's happening ... hopefully I will explain this properly.

On the Main Form, I have an 'Update Mode' button.  I must create a new form each time the update button is clicked because I need a new instance of the form with every possible update.  So I Dim one ...

Private Sub cmdUpdateMode_Click()
Dim frmWorkingPageVar As New frmWorkingPage

frmWorkingPageVar.lblWarningCaption = "You are Editing a Value"

etc etc etc

End sub

Now I have a new "dynamic" form called frmWorkingPageVar.  That's working fine.

Now the tricky part.  I am trying to launch a brand new form by clicking a checkbox on the frmWorkingPageVar form.  When I click the checkbox, I need to somehow send a variable from the frmWorkingPageVar.  This is where the error is being displayed.

When I click the checkbox, this is called:

Private Sub chkSendEmail_Click()
Dim frmEmailMessageVar As New frmEmailMessage

        Load frmEmailMessageVar
        frmEmailMessageVar.Show
       
End Sub

And this is what happens next:

Private Sub Form_Load()

    Call BuildEmailMessage

End Sub

...

Private Sub BuildEmailMessage()

    If frmWorkingPageVar.lblMgrUserID.Caption <> "" Then
        txtRecipient.Text = frmWorkingPageVar.lblMgrUserID.Caption
    Else
        txtRecipient.Text = ""
    End If

   etc etc

End Sub

I get "Object Required" run-time error 424, and the debug statement returns to highlight the first line of my "BuildEmailMessage" sub.

0
p_sieCommented:
You could use classes, where you store your info in.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GrahamSkanRetiredCommented:
The problem is that the scope your frmWorkingPageVar object is local to the cmdUpdateMode_Click sub on the MainForm

You can put a Form (or an frmWorkingPage) Object variable on the email form
Public Dim frmParent as Form

Private Sub chkSendEmail_Click()
Dim frmEmailMessageVar As New frmEmailMessage

        Load frmEmailMessageVar
       Set frmEmailMessagevar.frmParent = Me
        frmEmailMessageVar.Show
       
End Sub
0
EDDYKTCommented:
You can use this routine to find your form


Private Function findform(ByVal formname As String) As Form
Dim frm

For Each frm In Forms
If UCase(frm.Name) = formname Then
Set findform = frm
End If
Next
End Function

To call

dim frm

set frm = findform(ucase("DetailForm"))
0
pamartzCommented:
What I would do is store a reference to the caller form in a private variable in the called form.

I mean:

When you click the checkbox in frmWorkinPageVar you do:

Private Sub chkSendEmail_Click()
Dim frmEmailMessageVar As New frmEmailMessage

        Load frmEmailMessageVar
        frmEmailMessageVar.DoShow Me  ' Pass current frmWorkingVar form reference
       
End Sub

In frmEmailMessageVar the code would be:

Private frmCaller as frmWorkingPage

Public Sub DoShow(inCallerForm as frmWorkingPage)

    Set frmCaller = inCallerForm
    Call BuildEmailMessage

End Sub

...

Private Sub BuildEmailMessage()

    If frmCaller.lblMgrUserID.Caption <> "" Then
        txtRecipient.Text = frmCaller.lblMgrUserID.Caption
    Else
        txtRecipient.Text = ""
    End If

   etc etc

End Sub

And don't forget to clean up when you leave:

Private Sub Form_Unload
Set frmCaller = Nothing
End Sub

HTH,
 Pedro.
0
UPRRDevelopersAuthor Commented:
Thanks for the quick responses.  Any of these look like they would help me.  I'll split the points 100 each for all of your detailed responses.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.