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!