On Open Event - How to handle two Forms, that open up the same Main Form?

  • Thread starter cw via AccessMonster.com
  • Start date
C

cw via AccessMonster.com

I have two Forms, that open up the same frmCPUpdate:
------------------------------------------------------------
- frmCPtypeAndLataRS
- frmCPtypeAndLataRS_Static

When frmCPUpdate opens, the following code runs.
-------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Me.Requery
Me.CustomerName = [Forms]![frmCPtypeAndLataRS_Static]![CustName]
Me.Phone = [Forms]![frmCPtypeAndLataRS_Static]![PhoneNum]
Me.LATA = [Forms]![frmCPtypeAndLataRS_Static]![LataVal]
Me.City = [Forms]![frmCPtypeAndLataRS_Static]![CityVal]
Me.FicTN = [Forms]![frmCPtypeAndLataRS_Static]![FicTNVal]
Me.VerCircuit = [Forms]![frmCPtypeAndLataRS_Static]![Text78]
End Sub
-------------------------------------------------------------

This works fine from "frmCPtypeAndLataRS_Static" , but fails on the other,
because the Form name is "Hard-Coded" in my code above.

Question: How do I change this code, to handle both occurences of my forms?
Would I use some type of CASE IF/ELSE statement that determines the source
Form, then references the correct Form?

Thanks,
cw
 
B

Boyd Trimmell aka HiTechCoach via AccessMonster.co

cw said:
I have two Forms, that open up the same frmCPUpdate:
------------------------------------------------------------
- frmCPtypeAndLataRS
- frmCPtypeAndLataRS_Static

When frmCPUpdate opens, the following code runs.
-------------------------------------------------------------
Private Sub Form_Open(Cancel As Integer)
Me.Requery
Me.CustomerName = [Forms]![frmCPtypeAndLataRS_Static]![CustName]
Me.Phone = [Forms]![frmCPtypeAndLataRS_Static]![PhoneNum]
Me.LATA = [Forms]![frmCPtypeAndLataRS_Static]![LataVal]
Me.City = [Forms]![frmCPtypeAndLataRS_Static]![CityVal]
Me.FicTN = [Forms]![frmCPtypeAndLataRS_Static]![FicTNVal]
Me.VerCircuit = [Forms]![frmCPtypeAndLataRS_Static]![Text78]
End Sub
-------------------------------------------------------------

This works fine from "frmCPtypeAndLataRS_Static" , but fails on the other,
because the Form name is "Hard-Coded" in my code above.

Question: How do I change this code, to handle both occurences of my forms?
Would I use some type of CASE IF/ELSE statement that determines the source
Form, then references the correct Form?

Thanks,
cw


One possible solution would be to pass the form name in the open args
parameter.

To open the forn use:

DoCmd.OpenForm "rmCPUpdate", , , stLinkCriteria, , , "frmCPtypeAndLataRS"

or

DoCmd.OpenForm "rmCPUpdate", , , stLinkCriteria, , ,
"rmCPtypeAndLataRS_Static"


I would use the rmCPUpdate form's On Load event like this:


Private Sub Form_Load()

Me.Requery

Me.CustomerName = Forms(Me.OpenArgs)![CustName]
Me.Phone = Forms(Me.OpenArgs)![PhoneNum]
Me.LATA = Forms(Me.OpenArgs)![LataVal]
Me.City = Forms(Me.OpenArgs)![CityVal]
Me.FicTN = Forms(Me.OpenArgs)![FicTNVal]
Me.VerCircuit = Forms(Me.OpenArgs)![Text78]


End Sub
 
C

cw via AccessMonster.com

Boyd, Very nice. Worked!
I appreciate your help in learning a new procedure.
Thanks again..
cw
I have two Forms, that open up the same frmCPUpdate:
------------------------------------------------------------
[quoted text clipped - 23 lines]
Thanks,
cw

One possible solution would be to pass the form name in the open args
parameter.

To open the forn use:

DoCmd.OpenForm "rmCPUpdate", , , stLinkCriteria, , , "frmCPtypeAndLataRS"

or

DoCmd.OpenForm "rmCPUpdate", , , stLinkCriteria, , ,
"rmCPtypeAndLataRS_Static"

I would use the rmCPUpdate form's On Load event like this:

Private Sub Form_Load()

Me.Requery

Me.CustomerName = Forms(Me.OpenArgs)![CustName]
Me.Phone = Forms(Me.OpenArgs)![PhoneNum]
Me.LATA = Forms(Me.OpenArgs)![LataVal]
Me.City = Forms(Me.OpenArgs)![CityVal]
Me.FicTN = Forms(Me.OpenArgs)![FicTNVal]
Me.VerCircuit = Forms(Me.OpenArgs)![Text78]

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top