Results 1 to 3 of 3
  1. #1
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16

    Question DoCmd.OpenReport not working correctly?

    Two problems, one old, and now a new problem.



    Situation:
    We have a main Form that we use to enter information about students. Most of this info is stored in a table called Students and then a linked table called StudentPrograms (since a student can be in more than one program). We have a "Print this Record" button. Clicking on that opens up a report for that one student and we print that report out. However...if a student is in more than one program, then it opens up multiple copies of that student and would then print out extra copies. For example: If a student is in 3 different programs (that are listed on a sub Form on the main form) and we click on the Print button, it opens up 1 of 3 records all with that students information and printing from there would print out 3 copies of their information. We only want it to print out once. I tried added "Select Distinct" to the SQL of the report but it didn't work. That's the first problem.


    The new problem is that when we click on the Print button now, it asks for Parameters. Normally this is because fields do not match the SQL but I've looked through everything and can't see what the problem is. Hoping someone can suggest things that I could double check because I'm obviously missing something. Thanks.

    We made a lot of changes last week to the forms and tables. I fixed up the report to match the new renamed fields etc. But now when we click on the print button, Access asks us for parameters.

    Here is the codes that we've used and the errors:

    Code for the Print button:
    Private Sub cmdPrintButton_Click()
    On Error GoTo CmdPrintButton_Click_Err

    Dim strReportName As String
    Dim strCriteria As String

    strReportName = "rptStudent"
    strCriteria = "[DatabaseID]=" & Me![DatabaseID]
    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria


    CmdPrintButton_Click_Exit:
    Exit Sub


    CmdPrintButton_Click_Err:
    MsgBox Error$
    Resume CmdPrintButton_Click_Exit


    End Sub

    The SQL for the Form that has the print button:
    SELECT Students.*
    FROM Students;



    The SQL for the Student report:
    SELECT Students.*, StudentProgram.*
    FROM Students INNER JOIN StudentProgram ON Students.DatabaseID = StudentProgram.StudentIDLink;



    The parameters it is now asking us to enter:
    We get the popup that says Enter Parameter Value for the following items
    Students
    Students.DatabaseID
    Students.DatabaseID


    "Students" is a table, not a field so that's really puzzling me.

    Any suggestions would be greatly appreciated. thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    'Students' is being referenced somewhere as well as Students.DatabaseID (query criteria or textbox control source or in a query field calculation) and Access can't find corresponding field so it treats them as popup input parameters.

    If you want to provide db for analysis, follow instructions at bottom of my post. Be sure to identify the objects involved in issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16
    Thanks, that clued me in! The sub report was causing the problem. I deleted it and created another and it works fine now. I also changed the SQL of the main form to only select from the first table (since the subreport calls from the child table) and that fixed the duplicate reports showing up.

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

Similar Threads

  1. doCmd.OpenReport - Multiple Where Conditions
    By jml9012 in forum Programming
    Replies: 10
    Last Post: 05-20-2013, 08:45 PM
  2. DoCmd.OpenReport WHERE condition
    By bidbud68 in forum Programming
    Replies: 16
    Last Post: 10-19-2012, 05:31 AM
  3. Need help w/ docmd.openreport
    By jwill in forum Reports
    Replies: 3
    Last Post: 06-04-2012, 09:49 PM
  4. DoCmd OpenReport ... where condition with a Like
    By Grooz13 in forum Programming
    Replies: 4
    Last Post: 08-31-2010, 09:04 AM
  5. Can docmd.openreport print X copies on Y printer?
    By Coolpapabell in forum Reports
    Replies: 1
    Last Post: 09-02-2009, 08:35 AM

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