Reports in VB

DANY
08-11-2004, 04:43 PM
Hello to all,
I have never done reports in VB. I am connected to SQL and I want to add a report in VB with some groupings.

Assume I have a StoreProc and I have a parameter. User will enter the string value and then print the invoice. or a date range as a parameter.

Anyone with any vb sample.

thanks for helping.

ian99
08-11-2004, 05:03 PM
you want to use a data report, it's almost exactly like an access report.

in the code for the report, you'll have an initialize event. here you can simply bind your report to a recordset.

here's an example from one of mine. in mine i acutally create a disconnected recordset, fill it with data from a colletion, adn then bind it to my report. yours will be much easier since all you need to do is have a form, let the user enter values, then populate a recordset based on your SQL server query, and then open the report and have it bind to the recordset at the initalize event.

hope this helps! sorry it's end of day and i'm not thinking straight ;)

Public Sub DataReport_Initialize()
'set headings at top of report

Dim rs As New ADODB.Recordset 'recordset used to store data. we fill this with data from the
'modifiedCollection and then bind it to the report's datasource



'create recordset fields
rs.Fields.Append "Item_No", adDouble
rs.Fields.Append "Descrip", adBSTR
rs.Fields.Append "Day", adInteger
rs.Fields.Append "OldQty", adDouble
rs.Fields.Append "NewQty", adDouble
rs.Fields.Append "Type", adBSTR

'populate recordset with data

rs.Open
For Each myItem In modifiedCollection.Items

rs.AddNew
rs.Fields("Item_No") = myItem.itemNo
rs.Fields("Descrip") = myItem.Descrip
rs.Fields("Day") = myItem.day
rs.Fields("OldQty") = myItem.oldQty
rs.Fields("NewQty") = myItem.newQty
rs.Fields("Type") = myItem.itemType
rs.Update

Next




'set headings at top of report
Me.Sections.Item("section4").Controls.Item("lblCompany").Caption = typWCInfo(typWCIndex).Company
Me.Sections.Item("section4").Controls.Item("lblWorkcentre").Caption = typWCInfo(typWCIndex).Work_Centre

Me.Sections.Item("section4").Controls.Item("lblDateTime").Caption = Now()
Me.Sections.Item("section4").Controls.Item("lblReportCode").Caption = "MPS102-" & typWCInfo(typWCIndex).Company
Me.Sections.Item("section4").Controls.Item("lblUser").Caption = GetCurrentUserID()

rs.Sort = "day asc, item_no asc"
Set Me.DataSource = rs

'Me.Refresh
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum