Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unbound Reports in VB

Status
Not open for further replies.

julian92128

Programmer
Apr 26, 2001
5
US
I want to create a report with unbound fields and no database connection and then pass a recordset to the report and bound the fields but it gives me a Subscript out of range Error

this is my code i try to change the sample that cames with crystal and instead of using a datadisigner I want to use a recordset.

Dim m_Report As New crUnboundFields
Dim adoRs As ADODB.Recordset
' *************************************************************
Private Sub Form_Load()
Dim cnn As Connection
Set cnn = New Connection
Set adoRs = CreateObject("ADODB.Recordset")
cnn.ConnectionString = "DSN=Xtreme Sample Database"
cnn.Open
adoRs.Open "SELECT * FROM Orders", cnn
m_Report.Database.SetDataSource adoRs
' Bind the five unbound fields to the newly added data source
With m_Report
.UnboundString1.SetUnboundFieldSource "{Orders.Ship Via}"
.UnboundCurrency1.SetUnboundFieldSource "{Orders.Order Amount}"
.UnboundBoolean1.SetUnboundFieldSource "{Orders.Shipped}"
.UnboundNumber1.SetUnboundFieldSource "{Orders.Customer ID}"
.UnboundDate1.SetUnboundFieldSource "{Orders.Order Date}"
End With
' View the report
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub
 
I have the exact problem that Julian has experienced. Has anyone come up with the solution or a work around?

Any help would be appreciated.

Craig Adams
 
here is your code. i made some changes to it. copy and paste this code to your program.

'CrystalReport1 is the DSR under designers in your project 'you need to change this to your DSR name.


Dim m_Report As New CrystalReport1
Dim adoRs As ADODB.Recordset

'***********************************************************

Private Sub Form_Load()


Set adoRs = CreateObject("ADODB.Recordset")

adoRs.Open "SELECT * FROM Orders", "DSN=Xtreme Sample Database"

m_Report.Database.AddADOCommand adoRs.ActiveConnection, adoRs.ActiveCommand
' Bind the five unbound fields to the newly added data source

With m_Report
.UnboundString1.SetUnboundFieldSource "{ado.Ship Via}"
.UnboundCurrency1.SetUnboundFieldSource "{ado_Order Amount}"
.UnboundBoolean1.SetUnboundFieldSource "{ado.Shipped}"
.UnboundNumber1.SetUnboundFieldSource "{ado.Customer ID}"
.UnboundDate1.SetUnboundFieldSource "{ado_Order Date}"
End With

' View the report
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top