Passing on a value on an existing Access Report

I'm currently fighting with an Access 2002 Report. Here's the thing... I've created a report based on a query i've created. The query itself displays a series of receipts which have been added to the database via certain form. However, the user wanted to interact with the Report in a way that he could determine the content of the report by selecting a period between x and y.

I've done so by creating a Date Selection form which would pass a "WhereClause" to the Report in question displaying only the desired content. The next request was to have a total amount of receipts as well as the total price mentioned at the bottom of the page.

So far i've added these two fields as "Unbound" at the page footer and i'm trying to pass on the information from a SQL Statement into the newly created field. Here's the code i have so far (this code is located under the "OK" button of the form where the user can select the desired period):

Private Sub cmdOK_Click()
On Error GoTo Err_cmdOK_Click

If Me![txtFrom] <> "" And Me![txtTill] <> "" Then

    Set con = Application.CurrentProject.Connection
    Set RS = CreateObject("ADODB.Recordset")
    Set RSTotal = CreateObject("ADODB.Recordset")
    stSql = "SELECT * FROM [Ubersicht] "
    stSql = stSql & "WHERE (((Ubersicht.Kremationstag)>=#" & Me![txtFrom] & "#) AND ((Ubersicht.Kremationstag)<=#" & Me![txtTill] & "#))"
    RS.Open stSql, con, 1    ' 1 = adOpenKeyset
    RSTotal.Open "SELECT COUNT(KremationID) FROM [Ubersicht]", con, 1
   
    If RS.RecordCount > 0 Then
        DoCmd.OpenReport "Ubersicht", acViewPreview, , "[Kremationstag]>=#" & Me![txtFrom] & "# AND [Kremationstag]<=#" & Me![txtTill] & "#"
        Reports![Ubersicht].Controls![txtTotalKrem] = RSTotal.Fields(0)
        MsgBox RSTotal.Fields(0) & ", " & Reports![Ubersicht].Controls![txtTotalKrem]
   
        DoCmd.RepaintObject
        DoCmd.Maximize
    Else
        MsgBox "Date not found.", vbCritical + vbOKOnly
    End If
   
    DoCmd.Close acForm, Me.Name
Else
    If Me![txtFrom] = "" And Me![txtTill] = "" Then MsgBox "Please fill in a date.", vbCritical + vbOKOnly
    If Me![txtFrom] = "" Then MsgBox "Please fill in the ""From"" date.", vbCritical + vbOKOnly
    If Me![txtTill] = "" Then MsgBox "Please fill in the ""Till"" date.", vbCritical + vbOKOnly
End If

'Error Handling section
   
End Sub

Every thing goes well, except for one thing... The Report pops up and only displays the records from the desired period, but... "Reports![Ubersicht].Controls![txtTotalKrem].ControlSource = RSTotal.Fields(0)" should pass on the SELECT COUNT(x) into the Total Records field located at the page footer. According to the "MsgBox RSTotal.Fields(0) & ", " & Reports![Ubersicht].Controls![txtTotalKrem]", the COUNT information is passed on, but the report refuses to display it.

I figured it had something to do with the fact that the report is already being displayed, so i forced a repaint on the report, but alas... The COUNT value still does not appear on screen. The funny thing is, that when i print the report, the COUNT value is mentioned on the actual print out.

So, after that i tried to switch the code for passing on the COUNT value and actually opening the report, but then Access informs me that the Report does not exist or hasn't been opened yet. (-_-; )

At the moment i've used the DoCmd.RepaintObject command, but i get the feeling that there is another way to force a repaint... Does any one have experienced this perculiar "problem" before



Answer this question

Passing on a value on an existing Access Report

  • Passing on a value on an existing Access Report