VB and RB 4.2

forum.reportbuilder (2000-2005) & forum.td.reportbuilder (2005-2010)
Kees Velthuijs

VB and RB 4.2

Post by Kees Velthuijs » 02 Mar 2008, 21:52

 Posted by:  Kees Velthuijs 

Hello,
I'm trying to call RB4.2 from Visual Basic. In the end I want to use
templates, but for now I am using report files.

I have two questions:

1. The "rptDoc.Print" command shows the error "Object doesn't support this
property or method". How do you avoid this error?

2. I want to use templates. How do I change the code to use the template
"BlaBla.qrp"?

With regards,

KC

This is the code I use (It's VBA so you can paste it into Excel)

Sub Main()
On Error GoTo errMain

Dim rptAppl As ReportBuilder.Application
Dim rptDocs As ReportBuilder.Documents
Dim rptDoc As ReportBuilder.Document

Set rptAppl = New ReportBuilder.Application
rptAppl.Show

'Create new document
Set rptDocs = rptAppl.Documents
Set rptDoc = rptDocs.Add
rptDoc.CreateReportSkeleton

'Connect to the database
rptDoc.SetDatabase ("MVL00001")
rptDoc.SetLoginName ("ODBC")
rptDoc.SetPassword ("ODBC")
rptDoc.OpenConnection
If rptDoc.IsConnected Then

'Open report file
rptDoc.OpenReportFile ("C:\BlaBla.cqt")

'Activate query
rptDoc.ExecuteQuery
rptDoc.ResetPreview
rptDoc.SetDesignMode (False)

'Print the report on the default printer
rptDoc.SetUseDefaultPrinter (True)
rptDoc.Print
Else
MsgBox "not connected"
End If

errMain:
'Signal any error
If Err.Number 0 Then
MsgBox Err.Description
End If

'Close the connection if any
If rptDoc.IsConnected Then
rptDoc.CloseConnection
End If

'Close the document
rptDoc.Close (False)
Set rptDoc = Nothing

'If the last document is closed, quit application
If rptDocs.Count = 0 Then
rptAppl.Quit
End If
End Sub

Return to “td.reportbuilder”

Who is online

Users browsing this forum: [Ccbot] and 0 guests