Start New Discussion within our Software Development Community

I am desparate, please can someone tell me how I can change a report title in an Access 2000 report from within my VB6 code?

I did something like this but it is not changing thye title

Sub PrintReport(TheReport As String, TheCriteria As String, TheHeading As String)
    '-------------------------  If access is open then close it  --------------
    On Error Resume Next
    objAccess.Quit
    On Error GoTo NoRecords
    '-------------------------  Open Database  --------------------------------
    Set objAccess = New Access.Application
    objAccess.Visible = True
    objAccess.OpenCurrentDatabase (DatabasePath)
    objAccess.RunCommand acCmdAppMaximize
    '-------------------------  Open Report and set the Heading  --------------
    objAccess.DoCmd.OpenReport TheReport, acViewPreview, , TheCriteria
   If TheHeading <> "" Then
        objAccess.Reports(TheReport).Controls!lblHeading.Caption = TheHeading
    End If
    '-------------------------  Set the criteria for report  ------------------
    If TheCriteria <> "" Then
        objAccess.Reports(TheReport).Filter = TheCriteria
        DoEvents
    End If
    objAccess.Reports(TheReport).FilterOn = True
    DoEvents
    objAccess.DoCmd.Maximize
    objAccess.Visible = True
    Exit Sub
NoRecords:
    If Err.Number = 2486 Then
        Resume
    Else
        MsgBox "There are no records that match your request.", vbExclamation, "No Records"
    End If
End Sub

I'm sure it's just something simple, like maybe try refreshing the report after you set the label value? If your really desperate, create a table linked to the table which your report is pulling from to hold different title values and update the table prior to calling your report. Base your report off a query which then pulls your original data plus the newly updated title from the related table.

This article has been dead for over six months. Start a new discussion instead.