Link to home
Start Free TrialLog in
Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

asked on

Determine which form called the report - so I can reopen on close of report

Looking for code to determine which form called the report - so I can reopen on close of report.

What is the proper syntax I have two different forms that can call the report?  I need to return to that form on close of the active report..

Forms names are FE_ITPR and FE_ITPR_Enovia.

The current code is asking the user if they wish to return to the previous form or back to the Main Menu.  This is why I need to determine which form was the last active.

Thanks,
k
Private Sub Report_Close()
    Dim frm As Form
    DoCmd.Minimize
    
    Select Case MsgBox("Click Yes if you wish to return to previous form." _
                       & vbCrLf & "" _
                       & vbCrLf & "Click No, to return to Main Menu." _
                       , vbYesNo Or vbQuestion Or vbDefaultButton1, "What do you want to do?")
     Case vbYes
 If Forms![FE_ITPR_Enovia]![ITPR Detail].Form.Visible = True Then
        frm = Me.Parent.active
        If frm.Visible = False Then
            frm.Visible = True
        End If
 Else
        If Forms!FE_ITPR.Visible = False Then
            Forms!FE_ITPR.Visible = True
        End If
 End If
    Case vbNo
        If Forms!FS_MSB.Visible = False Then
            Forms!FS_MSB.Visible = True
            DoCmd.Close acForm, "FE_ITPR", acSaveYes
        End If
    End Select
    DoCmd.Restore
End Sub

Open in new window

Avatar of 2toria
2toria
Flag of United Kingdom of Great Britain and Northern Ireland image

If you're using VBA to open the report you can use the OpenArgs property to identify the form that called the report like this:-

DoCmd.OpenReport "Yourreport", , , , , "YourForm"

Then, when you close the report, just reference the openargs property again when the form is closed:-

docmd.openform Forms(OpenArgs)

And that should pretty much do the trick.
Matt
Avatar of Karen Schaefer

ASKER

how do I modify the code to inlcude the form name?

    DoCmd.OpenReport "R_ITPR_Release", acViewPreview, "", "", acNormal,
      DoCmd.OpenForm Forms(OpenArgs), acNormal, , , acFormEdit

I am getting wrong data type error.
here is what I have so far

I tried setting a variable to pass the form name - without success.

also

DoCmd.Close acForm, Forms(OpenArgs), acSaveYes
 
Was not successful - did not like the syntax.

any Ideas?

K
Private Sub Report_Close()
    Dim nFrm As Form
    DoCmd.Minimize
    
        Set nFrm = Forms(OpenArgs)
   Debug.Print nFrm
    Select Case MsgBox("Click Yes if you wish to return to previous form." _
                       & vbCrLf & "" _
                       & vbCrLf & "Click No, to return to Main Menu." _
                       , vbYesNo Or vbQuestion Or vbDefaultButton1, "What do you want to do?")
    Case vbYes
        Forms(OpenArgs).Visible = True
    Case vbNo
        If Forms!FS_MSB.Visible = False Then
            Forms!FS_MSB.Visible = True
            DoCmd.Close acForm, Forms(OpenArgs), acSaveYes
        End If
    End Select
    DoCmd.Restore
End Sub

Open in new window

how do I close using the OpenArgs - what is the proper syntax?

K
Avatar of Rey Obrero (Capricorn1)
open the report with this


DoCmd.OpenReport "R_ITPR_Release", AcView:=acViewPreview, OpenArgs:=Me.Name


Private Sub Report_Close()


    Select Case MsgBox("Click Yes if you wish to return to previous form." _
                       & vbCrLf & "" _
                       & vbCrLf & "Click No, to return to Main Menu." _
                       , vbYesNo Or vbQuestion Or vbDefaultButton1, "What do you want to do?")
    Case vbYes
        Forms(me.OpenArgs).Visible = True
    Case vbNo
 
    End Select
    DoCmd.Restore
End Sub
Thanks, how do I close using the OpenArgs - what is the proper syntax? on the case vbNo


    Case vbNo
        If IsFormLoaded(Forms(OpenArgs)) = True Then
            DoCmd.Close
        End If
        If IsFormLoaded(Forms!FS_MSB) = True Then
            Forms!FS_MSB.Visible = True
 '           DoCmd.Close acForm, nrm, acSaveYes
        End If
    End Select
    DoCmd.Restore
End Sub

K
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks that did the trick.

Karen