Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318

    Code for Parameter Form

    I currently have a parameter form named "Fm_Commander_Parameter" and a report named "Rpt_Bldgs_by_Commander".



    On the parameter form I have a unbound drop down. On the After Update have I this code that opens the report.

    Private Sub Cmb_Commander_AfterUpdate()
    DoCmd.OpenReport "Rpt_Bldgs_by_Commander", acViewPreview
    DoCmd.Close acForm, "Fm_Commander_Parameter"
    End Sub

    In the Query for the report for the Commander field I have the parameter as [Forms]![Fm_Commander_Parameter]![Cmb_Commander]

    I do not know how to write code very well and am unsure this can be done, but what I would like to do is remove the 'After Update' on the form and on 'Open' of the report I would like to write a code to go to the form, allow them to select the commander, then go back to the report query with the selection. This way I could use the Parameter Form with other reports. Below is the code I've come up with that will be place in 'Open' on the report.

    Private Sub Report_Open(Cancel As Integer)
    DoCmd.OpenForm "Fm_Commander_Parameter", acNormal
    (I don't know what to enter to keep the form open to enter the data. Without the below command it will run the report but the parameter form stays open.)
    DoCmd.Close acForm, "Fm_Commander_Parameter"
    End Sub
    Last edited by Huddle; 02-24-2012 at 03:39 PM.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You can actually use the same form doing it your original way. I often use one, using OpenArgs to pass the report to open:


    DoCmd.OpenForm "frmReportCriteria", , , , , , "rptCharterActivity"

    then in the code of that form:

    DoCmd.OpenReport OpenArgs, acViewPreview

    You can do it the way you are trying to. Look at help for OpenForm; you want the acDialog argument.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    I am getting this error

    Run-time error '2497: the action or method requires a Report Name argument.

    This is what I placed in Open of the Rpt_Bldgs_by_Commander

    Private Sub Report_Open(Cancel As Integer)
    DoCmd.OpenForm "Fm_Commander_Parameter", , , , , , "Rpt_Bldgs_by_Commander"
    End Sub


    This is what I place in After Update of the Fm_Commander_Parameter

    Private Sub Cmb_Commander_AfterUpdate()
    DoCmd.OpenReport OpenArgs, acViewPreview
    End Sub

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You have it reversed. Let's start with which method you want to use; form opens report, or report opens form?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    I want to open the report, have it open the form, put the data in the form, then show the results of the report after the query runs.

    I don't guess it would have to open the report first if I can use the form for multiple reports. Maybe I'm not getting the logic here.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    For your way the report's open event has:

    DoCmd.OpenForm "Fm_Commander_Parameter", , , , , acDialog

    The acDialog makes the report wait for the form to be closed or hidden before it continues. Since your query is looking for the form, you want to hide it when the user is done entering criteria:

    Me.Visible = False

    You can either leave it hidden until you need it again or close it in the report's close event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    So how do I tell the form to open whichever report I'm working with.

    When I enter the below code in the parameter form it tells me I need a report name but that takes me back to square one where I have to have a parameter form for each report.

    Private Sub Cmb_Commander_AfterUpdate()
    DoCmd.OpenReport OpenArgs, acViewPreview
    End Sub

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    OpenArgs was for the other method, where you open the form first, using OpenArgs to tell the form what report you want it to open. In the method you requested, you're already opening the report, and the report is opening the form. The form doesn't need to know what report opened it. Your button on the form would just hide it, which would let the report finish opening.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    Oh I got it. The Me.Visible = False goes on the form not the report.....Thanks

  10. #10
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    I've come across another problem. When the parameter form comes up it contains the last selection made. I've tried a requery in the form on load and before update. I've also tried to requery on the report exiting. It causes other problems.

    If the previous entry is "Beach" and I want to select Beach again I have to do a drop down selection again. It doesn't read the previous selection even though that it what is in the field. I want to have the form blank when it opens.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    Is it bound to a table? Mine generally aren't.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    The combo box is connected to a look up table.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    But does it have anything in the Control Source property? If not, closing/opening the form should blank the combo. If you're only hiding it, you'd need to blank it yourself, probably in the activate event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Huddle is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    318
    I didn't have a closing code. Fixed that. So below is what I've got.

    In the parameter form:
    Private Sub Cmb_Commander_AfterUpdate()
    Me.Visible = False
    End Sub


    In the Report:
    Private Sub Report_Close()
    DoCmd.Close acForm, "Fm_Commander_Parameter", acSaveNo
    End Sub
    Private Sub Report_Open(Cancel As Integer)
    DoCmd.OpenForm "Fm_Commander_Parameter", , , , , acDialog
    End Sub

    If I want the report to open in a print preview default how do I add that?

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    The default view is a property of the report, but typically in the code that opens the report you specify the desired view. It's one of the arguments of OpenReport.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Parameter Form
    By DebbieC in forum Reports
    Replies: 4
    Last Post: 01-24-2012, 11:19 AM
  2. Replies: 13
    Last Post: 01-10-2012, 09:56 AM
  3. Parameter field in Form
    By darryaz in forum Forms
    Replies: 2
    Last Post: 11-20-2011, 12:38 PM
  4. Automatically Update Query Parameter w/ Code
    By benthamq in forum Programming
    Replies: 2
    Last Post: 08-20-2011, 03:46 PM
  5. Replies: 10
    Last Post: 09-27-2010, 08:06 PM

Tags for this Thread

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