Solved Passing form in OpenArgs (3 Viewers)

ClaraBarton

Registered User.
Local time
Today, 15:45
Joined
Oct 14, 2019
Messages
531
I want to pass the name of my form to the report it's calling. The calling button is on the 2nd sub form.
So I've tried
Me.Parent.Parent.Form.Name

Dim frm as Form
Set frm as Forms!frmAAAA

OpenArgs = Me.Name

the following:
Code:
Dim frm As String
frm = "Forms!frmAAAA"
    Me.Requery
    
    DoCmd.OpenReport _
        ReportName:="rptInvoice", _
        View:=acViewPreview, _
        WhereCondition:="InvoiceID = " & Me!InvoiceID, _
        OpenArgs:=frm
    Debug.Print OpenArgs
    Forms!frmAAAA.Visible = False
None of these work. How do I do this?
 
I use it on the report to make it visible when I close the report. Usually I just use Me.Name but this button is down in the 2nd subform.
 
I use it on the report to make it visible when I close the report. Usually I just use Me.Name but this button is down in the 2nd subform.
What do you mean by 2nd subform? Is it a form inside a form that's inside the main form?
 
yes. Main Form -- frmAAAA
Sub Form 1 -- frmsubDetail
Sub Form 2 -- frmsubInvoice -- Here is where the report button is.
So, you would think Me.Parent.Parent.Form.Name
 
Here's a function that returns a reference to the main form...
Code:
Function GetMainForm(obj As Object) As Access.Form
On Error GoTo handler
    Set GetMainForm = GetMainForm(obj.Parent)           ' MainForm has no parent
    Exit Function
handler:
    Set GetMainForm = obj
End Function
You can pass it any form or control object, and it will crawl up the hierarchy until it finds an object without a parent. That object is the main form.
 
if you have 2 subforms:

Me.Parent.Name

if frmsubInvoice is embedded as sub-subform to subform frmsubDetail:

Me.Parent.Parent.Name
 
The OpenArgs parameter is text and has to be manipulated - obvious values such as number use default casts.
 
OpenArgs:=Me.Parent.Parent.Name returns null
Function getmainform...
How do you use it?
OpenArgs:=GetMainForm ?
OpenArgs:=obj ?

I want to manipulate.... just can't figure how!
 
Code:
Dim frm As String
frm = "Forms!frmAAAA"
    Me.Requery
   
    DoCmd.OpenReport _
        ReportName:="rptInvoice", _
        View:=acViewPreview, _
        WhereCondition:="InvoiceID = " & Me!InvoiceID, _
        OpenArgs:=frm
    Debug.Print OpenArgs
    Forms!frmAAAA.Visible = False
None of these work. How do I do this?

Amend to:
Code:
Dim frm As String
frm = "frmAAAA"
    Me.Requery
   
    DoCmd.OpenReport _
        ReportName:="rptInvoice", _
        View:=acViewPreview, _
        WhereCondition:="InvoiceID = " & Me!InvoiceID, _
        OpenArgs:=frm
    Debug.Print OpenArgs
    Forms(Me.OpenArgs).Visible = False
 
If the above code is being called from the module of frmAAAA then you can more simply use:
Code:
    Me.Requery
  
    DoCmd.OpenReport _
        ReportName:="rptInvoice", _
        View:=acViewPreview, _
        WhereCondition:="InvoiceID = " & Me!InvoiceID, _
        OpenArgs:=Me.Name
    Debug.Print OpenArgs ' - this refers to the calling form's openArgs, NOT rptInvoice's OpenArgs!!!
    Me.Visible = False
 
OpenArgs:=Me.Parent.Parent.Name returns null
Function getmainform...
How do you use it?
OpenArgs:=GetMainForm ?
OpenArgs:=obj ?

I want to manipulate.... just can't figure how!
Just curious, what does Me.Parent.Name return?
 
Yes... Me.Name is what I usually use. However, I'm calling from the sub, sub form
 
OH OH OH!!! Now I just feel stupid! Me.Parent.Parent.Name returns frmAAAA! I did not realize I needed to check the report's openargs. THANK YOU SO MUCH... ALL
 

Users who are viewing this thread

Back
Top Bottom