Hi everybody,
[Access 2010 .mdb]
I'm working with a report and I'm trying to create a standard module function that will reduce the amount of code typed into expressions on the report (since the expressions are essentially the same, save for one piece of info).
On the report, there are 11 text boxes that are identical that I've named Col1, Col2, Col3, etc. These text boxes have the following control source, where the value in the square brackets is a field that is bound to the record source for the report:
I have another 11 text boxes that are identical that I've named PercentABC, PercentDEF, etc. These textboxes HAD the following control source:
I wanted to create a standard module function to reduce to cut the above code down to a single line. The function would pass in the [Col1] value and the [srptTimelinessT otalsByProgram].[Report]![ABC] to the function, and the function would carry out the other steps.
One caveat, some of the programs may not have ever had any records, so the field on the subreport has to be passed in to the function and not the value in the field, otherwise it displays as #Type on the report.
I tried the following without success, but I'm hoping it will help explain what I'm trying to accomplish:
I get the error message that says the subreport item is closed or doesn't exist when I try to run this.
Because of this, I think I need to pass the actual field from the subreport to the function instead of a string since I can't set a field object for a field on a subreport. I just don't know how to accomplish this.
Thanks,
beacon
[Access 2010 .mdb]
I'm working with a report and I'm trying to create a standard module function that will reduce the amount of code typed into expressions on the report (since the expressions are essentially the same, save for one piece of info).
On the report, there are 11 text boxes that are identical that I've named Col1, Col2, Col3, etc. These text boxes have the following control source, where the value in the square brackets is a field that is bound to the record source for the report:
Code:
=IIf(IsNothing([ABC]),0,[ABC])
Code:
//This is basically an expression that checks for a value //or rounds to a certain number of decimal places. =IIf(([Col1]=0) And ([srptTimelinessTotalsByProgram].[Report]![ABC]=0 Or IsNothing([srptTimelinessTotalsByProgram].[Report]![ABC])),0, IIf(([Col2]/[srptTimelinessTotalsByProgram].[Report]![ABC]>0.00000001) And ([Col1]/[srptTimelinessTotalsByProgram].[Report]![ABC]<0.05),([Col1]/[srptTimelinessTotalsByProgram].[Report]![ABC])+0.005, [Col1]/[srptTimelinessTotalsByProgram].[Report]![ABC]))
One caveat, some of the programs may not have ever had any records, so the field on the subreport has to be passed in to the function and not the value in the field, otherwise it displays as #Type on the report.
I tried the following without success, but I'm hoping it will help explain what I'm trying to accomplish:
Code:
//The expression is =TimelinessPercent([Col1],"ABC"]
Code:
//My attempt at the standard module function
Public Function TimelinessPercent(col As Long, prog As String)
Dim fld As Field
Select Case Program
Case "ABC"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!ABC
Case "DEF"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!DEF
Case "GHI"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!GHI
Case "JKL"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!JKL
Case "MNO"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!MNO
Case "PQR"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!PQR
Case "STU"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!STU
Case "VWX"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!VWX
Case "YZA"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!YZA
Case "BCD"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!BCD
Case "EFG"
Set fld = Reports!rptTimeliness!srptTimelinessTotalsByProgram.Report!EFG
End Select
Debug.Print "str: " & prog & " col: " & col & " fld: " & fld
If (col = 0) And (fld = 0 Or IsNothing(fld)) Then
TimelinessPercent = 0
ElseIf (col / fld > 0.00000001) And (col / fld < 0.05) Then
TimelinessPercent = (col / fld) + 0.005
Else
TimelinessPercent = col / fld
End If
End Function
Because of this, I think I need to pass the actual field from the subreport to the function instead of a string since I can't set a field object for a field on a subreport. I just don't know how to accomplish this.
Thanks,
beacon
Comment