Help with not null & DoCmd.OpenReport (1 Viewer)

L

lindsRed

Guest
Hi, I need some help from someone a bit more experienced than me.

I have set up a school student database. I have a print command form with some code which prints out reports for the selected student. However some students do not take some subjects but in my current code when I open the reports, all the reports open. I want to add an Is Not Null statement or something like that but don't know how. In other words I want only the reports to open and then print if the students name is present. This is my current code: (oh I've set it to acViewPreview at the moment while I test it so it doesn't jam up my printer!)

Private Sub StudentReportCombo_AfterUpdate()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "This will automaticaly print out all the subject reports for the selected Student." & Chr(13) & Chr(13) & "Do you want to continue?" ' Define message.
Style = vbYesNo + vbExclamation ' Define buttons.
Title = "Printing Whole Year Missing Codes" ' Define title.


Response = MsgBox(Msg, Style, Title)
If Response = vbYes Then ' Print the reports for all subjects

DoCmd.OpenReport "rptArt", acViewPreview, "", "[tblArt]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptArt", acSaveNo

DoCmd.OpenReport "rptDrama", acViewPreview, "", "[tblDrama]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptDrama", acSaveNo

DoCmd.OpenReport "rptDTFoodTech", acViewPreview, "", "[tblDTFoodTech]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptDTFoodTech", acSaveNo

DoCmd.OpenReport "rptDTProdDes", acViewPreview, "", "[tblDTProdDes]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptDTProdDes", acSaveNo

DoCmd.OpenReport "rptDTResMat", acViewPreview, "", "[tblDTResMat]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptDTResMat", acSaveNo

DoCmd.OpenReport "rptDTText", acViewPreview, "", "[tblDTText]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptDTText", acSaveNo

DoCmd.OpenReport "rptEnglish", acViewPreview, "", "[tblEnglish]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptEnglish", acSaveNo

DoCmd.OpenReport "rptFrench", acViewPreview, "", "[tblFrench]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptFrench", acSaveNo

DoCmd.OpenReport "rptGeography", acViewPreview, "", "[tblGeography]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptGeography", acSaveNo


DoCmd.OpenReport "rptGerman", acViewPreview, "", "[tblGerman]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptGerman", acSaveNo


DoCmd.OpenReport "rptHistory", acViewPreview, "", "[tblHistory]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptHistory", acSaveNo


DoCmd.OpenReport "rptICT", acViewPreview, "", "[tblICT]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptICT", acSaveNo

DoCmd.OpenReport "rptMaths", acViewPreview, "", "[tblMaths]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptMaths", acSaveNo


DoCmd.OpenReport "rptMusic", acViewPreview, "", "[tblMusic]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptMusic", acSaveNo


DoCmd.OpenReport "rptPE", acViewPreview, "", "[tblPE]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptPE", acSaveNo


DoCmd.OpenReport "rptPSE", acViewPreview, "", "[tblPSE]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptPSE", acSaveNo


DoCmd.OpenReport "rptRE", acViewPreview, "", "[tblRE]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptRE", acSaveNo


DoCmd.OpenReport "rptScience", acViewPreview, "", "[tblScience]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptScience", acSaveNo

DoCmd.OpenReport "rptSpanish", acViewPreview, "", "[tblSpanish]![Name FS] =[Forms]![frmPrintSelectClass]![StudentReportCombo]"
' DoCmd.Close acReport, "rptSpanish", acSaveNo

Else ' Do nothing


End If
End Sub

So I want the code to check all tables and if the student's name is present then open the report - at the moment I get a load of blank reports with no data when the student does not take that subject. Sorry to be a pain and I hope this is understood!!
Cheers, Linds:confused:
 

KenHigg

Registered User
Local time
Yesterday, 19:53
Joined
Jun 9, 2004
Messages
13,327
Q1. Are all these reports basically the same with the exception of the data they contain?
 

Oldsoftboss

AWF VIP
Local time
Today, 09:53
Joined
Oct 28, 2001
Messages
2,499
A report has a NoData event

on the form combo add this error handler"

Private Sub StudentReportCombo_AfterUpdate()
On error resume next
'If you dont a cancel error will be displayed



Then in each report add the code:


Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Err_Report_NoData

'Use the Msgbox if you want
MsgBox "There is no data for this report. Canceling report...", vbInformation, " No Data"
Cancel = True

Exit_Report_NoData:
Exit Sub

Err_Report_NoData:
MsgBox Err.Description, , " Error"
Resume Exit_Report_NoData

End Sub
 

Users who are viewing this thread

Top Bottom