View Full Version : pass variable to report


teel73
07-31-2008, 11:47 AM
I'm trying to simply pass a variable to my report.

I have a report named "rptMonthlyStatistics". And a unbound control named "totCompleted". On Open event of the report I am calling a function named "getMonthlyStats". The code for that funtion is here:

Dim dbs As Database
Dim myqry As QueryDef
Dim rstCompleted As Recordset
Dim sql As String
Dim totCompleted As Integer
Dim rangeFrm As Form
Dim myStart, myEnd As String
Set dbs = CurrentDb
Set rangeFrm = Form_frmDateRange
myStart = rangeFrm!txtStart
myEnd = rangeFrm!txtEnd

sql = "SELECT Count(tblContractorDataOnly.Id) AS CountOfId " _
& "FROM tblContractorDataOnly INNER JOIN tblBackgoundReview ON tblContractorDataOnly.Id = tblBackgoundReview.Data_ID " _
& "WHERE(((tblBackgoundReview.BICompleted) Between #" & myStart & "# And #" & myEnd & "#) AND ((tblBackgoundReview.BIStatus)<>'EXEMPT'));"
Set myqry = dbs.CreateQueryDef("", sql)
Set rstCompleted = myqry.OpenRecordset(dbOpenSnapshot)
Reports!rptMonthlyStatistics!totCompleted = rstCompleted!CountOfID



I am simply trying to get the control on my report to display the number of records in my temp Query. "rstCompleted.countofID"

When I run my report it produces an error: "You can not assign a value to this object"

Below is the line that the code breaks on:
Reports!rptMonthlyStatistics!totCompleted = rstCompleted!CountOfID

How can I pass the value of rstCompleted.countOfID to my report?

RuralGuy
07-31-2008, 03:56 PM
Save the value in a local variable and put it in the control in the Format event of the section where the control is located. The Open Event of a report is too early to reference a control on the report.

teel73
08-05-2008, 05:12 AM
thank you buddy! that worked.

RuralGuy
08-05-2008, 08:54 AM
Glad I could help.

Lightwave
06-26-2009, 08:33 AM
Magic - this sorted the same problem out for me

RuralGuy
06-26-2009, 08:39 AM
The gift that keeps giving. Excellent!