Results 1 to 14 of 14
  1. #1
    Robert2150 is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    102

    Opening main form after viewing a report.

    I have a button on my main form that allows me to view one of my reports. In order to view the report I have to close my main form.


    My problem is how do I reopen my main form when I close the report that I have viewed?
    Does anyone have some code that would reopen my main form when clicking on the X in the upper right hand corner of the report to close it?

    Thank you in advance for any help you can give me.

    Robert2150

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I simply use VBA to export reports to PDF. In 2010 there is something called Report View. You should be able to put a command button in a report while in report view. Code behind could close the report and open your form.

  3. #3
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    102
    ItsMe,

    What VBA do you use to export reports to PDF?, it sounds like a good alternative.

    Robert2150

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have a temp folder for each user and when they create reports, code deletes the temp files and exports a new one.

    Something like this
    Code:
        Dim strPath As String
        Dim strKill As String
        
        strPath = "C:\Test"
        strKill = Dir(strPath & "*.pdf", vbHidden)
        'Delete the temporary files
        While strKill <> ""
            Kill strPath & strKill
            strKill = Dir(strPath & "*.pdf", vbHidden)
        Wend
    
    DoCmd.OutputTo acOutputReport, "rptReportName", acFormatPDF, strPath & "\FileName.PDF"
    Application.FollowHyperlink strPath & "\FileName.pdf", , True
    I have additional code that checks for and generates the temp folder. I also have code that checks if the user has one of the PDF's open before the app tries to delete it.

  5. #5
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Hi Robert,

    Another option you can do is on your report properties, in the OnClose event, you can add a OpenForm macro.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by cbende2 View Post
    Hi Robert,

    Another option you can do is on your report properties, in the OnClose event, you can add a OpenForm macro.
    That's not a bad idea. I avoid Macros so much I often underestimate their usefulness. I suspect you could do the same by adding VBA in the Report's Close event handler too.

  7. #7
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Yep, you definitely can.

  8. #8
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    ItsMe, why do more advanced developers avoid macros? I've been using access for about a year now and they just seem so convenient and helpful instead of writing vba for a button or something.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by cbende2 View Post
    ItsMe, why do more advanced developers avoid macros?
    When I first starting using Access, back around 2004 or so, I did not recognize the functionality I needed when using macros. So I was forced to learn VBA and became comfortable with it. As time went by, Macros became more prevalent. However, they are not always compatible across different versions of Access.

    Using Macro Objects within Access is considered a Tools Driven Approach to development. This approach to the architecture of an application is helpful for quickly getting your app to production but the benefits are offset with maintenance of the tools used. On the flip side, a maintenance driven approach is time consuming during development time. But, the long term benefits of using code behind are superior.

  10. #10
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    Quote Originally Posted by ItsMe View Post
    When I first starting using Access, back around 2004 or so, I did not recognize the functionality I needed when using macros. So I was forced to learn VBA and became comfortable with it. As time went by, Macros became more prevalent. However, they are not always compatible across different versions of Access.

    Using Macro Objects within Access is considered a Tools Driven Approach to development. This approach to the architecture of an application is helpful for quickly getting your app to production but the benefits are offset with maintenance of the tools used. On the flip side, a maintenance driven approach is time consuming during development time. But, the long term benefits of using code behind are superior.
    I see now, thank you for the explanation.

  11. #11
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    102
    ItsMe,

    Thanks for the input. However I have this database on a company server, and have a hundred or so users at numerous geographic locations, would I need a Temp folder for each user?

    Also, I couldn't see how this would re-open my main form, after viewing the report, I am more than likely missing something.

    On top of everything else, this process has to be very user friendly due to the various levels of experience with the various users.

    Thanks, Robert2150

  12. #12
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    102
    ItsMe,

    Do you have any suggestions on the VBA that you could add to the Report's Close Event handler? This may be the way to go seeing that I can get the Report Open, and the Main Form Closed. All I need to do is Reopen the Main Form upon closing the Report.

    Thanks, Robert 2150

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    You do not have to export to a PDF file. You can use the On Close event and embed a macro or use VBA code to open the form.

    VBA code in the Close event would look like
    DoCmd.OpenForm "FormName"

    To close a form that is open would look like
    DoCmd.Close acForm, "FormName"

    would I need a Temp folder for each user?
    Yes. IIRC I use temp folders on the server to avoid hyperlink warnings. But, you can use a temp folder on the user's machine. Either way, you would use additional code to check for an existing folder and create a folder if one did not exist. Then use the folder to create the PDF. It could be a thousand users and the code would not be any more complicated than for one user.
    Also, I couldn't see how this would re-open my main form, after viewing the report, I am more than likely missing something.
    I suppose you are correct. Whatever is causing the form to close is causing the need to open it. I was assuming you were using overlapping windows or had eliminated tabs and this was necessitating closing the other form or simply running code to bring it back on top.

    On top of everything else, this process has to be very user friendly due to the various levels of experience with the various users.
    That's why there are forms and event handlers. You create an event driven application and a graphic interface for the user's benefit. Opening a PDF in a new window is about as user friendly as it gets.

  14. #14
    Robert2150 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Location
    Sparks, Nv
    Posts
    102
    I have solved this issue with the following code: (Use your own report names, and form names.)

    Code #1
    Private Sub VIEW_EQUIPMENT_REPORT_Click()
    strWhere ="[Property Number] = " & Me.[Property Number]
    DoCmd.OpenReport "RESERVE REQUIREMENT REPORT", acViewPreview,, strWhere
    DoCmd.ShowToolbar "Ribbon",acToolbarNo
    DoCmd.CloseacForm, "ENLARGED PROP INFO", acSaveNo
    End Sub
    Code #2
    Also place following code in On Close for the RESERVEREQUIREMENT REPORT.
    Private Sub Report_Close()
    DoCmd.OpenForm "ENLARGED PROP INFO", acNormal
    End Sub
    Repeat for each report you want to view.

    Thanks everyone for your help

    Robert2150


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 02-05-2016, 02:32 PM
  2. Replies: 20
    Last Post: 05-19-2015, 05:10 AM
  3. Replies: 3
    Last Post: 12-04-2014, 10:12 AM
  4. Replies: 3
    Last Post: 05-02-2011, 07:34 AM
  5. opening a second form from main/subform
    By PJPCVP in forum Database Design
    Replies: 1
    Last Post: 10-29-2010, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums