R
Ruth Isaacs
Hello All
I have inherited a db with a fairly complex module that I am trying to
simplify. Essentally there are a lot (35) of reports in the db that are
generated for a given [practice]. The reports are uploaded to a website and
then sent as emails, and/or printed and posted, to the Practice. The report
is generated for a [practice] if the value of a corresponding yes/no field
(there are 35 such 'report' fields) on the current open form is 'yes', and
the email/print decision depends on the values of of two other yes/no fields
'printreports' and 'emailreports' on the curent form. Currently the module
first looks at the value of 'emaileports' and , if this is true, it then
looks at the value of each of the 35 yes/no 'report' fields and if this is
true some code if executed that converts the report to PDF then adds it to a
file (for later emailing and uploadng.
e.g. for the report called [rpt epping pcg] the corresponding yes/no
'report' field is called [epping rpt], and I have the following
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
flname = mth & "-Payroll-PS4 Substitute"
blret = ConvertReportToPDF(rptname, vbNullString, drname & flname &
".pdf", False)
DoCmd.RunSQL "INSERT INTO [" & strname & "] ( reportname ) SELECT "
& "'" & flname & "'" & " AS reportname "
End If
The trouble is that there are 35 'If' conditions like the one above that all
relate to the 'umbrella' condition that 'emailreports' is true: following
that, all 35 'If' conditions are then repeated for the 'umbrella' condition
that 'printreports' is true:
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
DoCmd.OpenReport rptname, acNormal, "", ""
End If
Is it possible to avoid all this repitition - also without repeating the
'printreports' and 'emailreports' conditions?
I wondered whether it would be possible to create an expression called
something like "reporting_method" that would be defined along the lines of:
If (Forms![frm practices]![emailreports] = True) Then
reporting_method =
flname = mth & "-Payroll-PS4 Substitute"
blret = ConvertReportToPDF(rptname, vbNullString, drname & flname &
".pdf", False)
DoCmd.RunSQL "INSERT INTO [" & strname & "] ( reportname ) SELECT "
& "'" & flname & "'" & " AS reportname "
Else
reporting_method =
DoCmd.OpenReport rptname, acNormal, "", ""
End If
.... and then to go through the 35 'report' conditions with something like:
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
reporting_method
End If
I realise this question has become rather long (!), but I very much hope
someone is still 'with it' and can help me work this out.
Many thanks in advance.
Leslie Isaacs
I have inherited a db with a fairly complex module that I am trying to
simplify. Essentally there are a lot (35) of reports in the db that are
generated for a given [practice]. The reports are uploaded to a website and
then sent as emails, and/or printed and posted, to the Practice. The report
is generated for a [practice] if the value of a corresponding yes/no field
(there are 35 such 'report' fields) on the current open form is 'yes', and
the email/print decision depends on the values of of two other yes/no fields
'printreports' and 'emailreports' on the curent form. Currently the module
first looks at the value of 'emaileports' and , if this is true, it then
looks at the value of each of the 35 yes/no 'report' fields and if this is
true some code if executed that converts the report to PDF then adds it to a
file (for later emailing and uploadng.
e.g. for the report called [rpt epping pcg] the corresponding yes/no
'report' field is called [epping rpt], and I have the following
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
flname = mth & "-Payroll-PS4 Substitute"
blret = ConvertReportToPDF(rptname, vbNullString, drname & flname &
".pdf", False)
DoCmd.RunSQL "INSERT INTO [" & strname & "] ( reportname ) SELECT "
& "'" & flname & "'" & " AS reportname "
End If
The trouble is that there are 35 'If' conditions like the one above that all
relate to the 'umbrella' condition that 'emailreports' is true: following
that, all 35 'If' conditions are then repeated for the 'umbrella' condition
that 'printreports' is true:
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
DoCmd.OpenReport rptname, acNormal, "", ""
End If
Is it possible to avoid all this repitition - also without repeating the
'printreports' and 'emailreports' conditions?
I wondered whether it would be possible to create an expression called
something like "reporting_method" that would be defined along the lines of:
If (Forms![frm practices]![emailreports] = True) Then
reporting_method =
flname = mth & "-Payroll-PS4 Substitute"
blret = ConvertReportToPDF(rptname, vbNullString, drname & flname &
".pdf", False)
DoCmd.RunSQL "INSERT INTO [" & strname & "] ( reportname ) SELECT "
& "'" & flname & "'" & " AS reportname "
Else
reporting_method =
DoCmd.OpenReport rptname, acNormal, "", ""
End If
.... and then to go through the 35 'report' conditions with something like:
If (Forms![frm practices]![epping rpt] = True) Then
rptname = "rpt epping pcg"
reporting_method
End If
I realise this question has become rather long (!), but I very much hope
someone is still 'with it' and can help me work this out.
Many thanks in advance.
Leslie Isaacs