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

Karen SchaeferBI ANALYSTAsked:
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.

2toriaCommented:
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
0
Karen SchaeferBI ANALYSTAuthor Commented:
how do I modify the code to inlcude the form name?

    DoCmd.OpenReport "R_ITPR_Release", acViewPreview, "", "", acNormal,
0
Karen SchaeferBI ANALYSTAuthor Commented:
      DoCmd.OpenForm Forms(OpenArgs), acNormal, , , acFormEdit

I am getting wrong data type error.
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.

Karen SchaeferBI ANALYSTAuthor Commented:
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

0
Karen SchaeferBI ANALYSTAuthor Commented:
how do I close using the OpenArgs - what is the proper syntax?

K
0
Rey Obrero (Capricorn1)Commented:
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
0
Karen SchaeferBI ANALYSTAuthor Commented:
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
0
Rey Obrero (Capricorn1)Commented:
post the codes that you used to open the reports..
are you hiding the form that calls the codes to open the report?


Private Sub Report_Close()
if me.openargs & ""<>"" then

    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
        ' Forms(me.OpenArgs).setFocus
    Case vbNo
       docmd.close acform, me.openargs
    End Select

end if
 
End Sub
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
Karen SchaeferBI ANALYSTAuthor Commented:
thanks that did the trick.

Karen
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
Microsoft Access

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.