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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a data report in VB6.0

Status
Not open for further replies.

PleaseGiveHelp

Programmer
Oct 29, 2002
131
US
I need to create a data report in VB. I'm new at this and not quite sure where to start. Do I need to create a data environment? And how do I specify the datasource and datamembers? If I am using a SQL query, do I need to specify the fields? As of now, my code is all within the code section of the data report and I"m not sure this is right. This is what I have:

Private Sub DataReport_Initialize()

Dim db As Connection
Set db = New Connection
db.CursorLocation = adUseClient
db.Open "blahblahblah;"
Set mpreport = rptmemoreport
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "select blah blah blah", db, adOpenStatic, adLockOptimistic
Set mpreport.DataSource = adoPrimaryRS

'mpreport.PrintForm

'mbDataChanged = False
'adoPrimaryRS.Close
'Set adoPrimaryRS = Nothing
'Unload rptmemoreport

End Sub

However when I try to then create the report, I can't figure out how to set up the fields to look at the data...its just empty. Help!
 
You need to do all the biz before you call the report. I do it on the calling form something like this ( assuming an open database connection called cn):

Dim mySQL As String
mySQL = "SELECT whatever from ThisTable Where This condition "
Set rst = New Recordset

With rst
Set rst.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open mySQL
End With

'Use this bit if you want to alter print orientation
dr1.Orientation = rptOrientLandscape

Set dr1.DataSource = rst

'Use this bit if you want to alter text in the header portion
With dr1.Sections(1)
.Controls.Item("lblDate").Caption = Date
.Controls.Item("lblFred").Visible = True
End With
'Show it now
dr1.Show
DoEvents
rst.Close
Set rst = Nothing

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
But can I create the data environment and then simply have the report with the 'calls' in the code behind the report? If so, how do I 'refer' to the data environment variables in the report code? In my data environment code I am connecting to a stored procedure.
 
Sorry I thought you were trying to avoid the DataEnvironment. If you want to use one, just set the DR datasource to the DE and set the DR Datamember to one of the DE commands.

You can set the DE command to a SQL statement etc from DE|Connection|add command and set properties from Command rightclick Properties.

If you do this first then in DR design when you add a rptTextBox, click on it's Datafield property and you'll get a dropdown choice of the fields returned by the Command object from DE
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
I see what you mean and for the most part I"ve done this but now its yelling at me once I get to the datamember part...it tells me its not a valid use of the property... this is what I have (note that my datamember is set to a stored procedure):

Private Sub DataReport_Initialize()

Set mpreport = rptmemoreport (set as public above)
Set mpreport.DataSource = DataEnvMemoPrint
Set mpreport.DataMember = proc_memo_print
mpreport.Show

End Sub
 
Have you tried setting Datamember property in the Properties window rather than in code? Mine works fine with a SP, including taking parameters.

I still set up the DE before I call the Report, rather than in the Report Initialise event, but I don't know if that makes a difference
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
You're right. I think because I had it in there twice (the same code) it was getting confused. So it works now for the most part..the only thing is, my report should bring back multiple pages and for some reason it is only returning one page...the first row returned from the stored procedure. Why is this? How can I get all of my pages?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top