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

printing for a recordset 2

Status
Not open for further replies.

raja130

Technical User
Oct 7, 2004
5
0
0
US
I want to search a table for records between two dates and then print the result of the search. I proform the search using an SQL between statement and display the result in a listview box this part work fine. I just don't know how to print the recordset?
This is what I have so far.

Set rsTemp = new ADODB.Recordset
rsTemp.Open "(My SQL statement)"

How can I pass the recordset to Data Report to preview and print the result? or Just Print the result in the recordset

Any help will be Greatly Appreciated

Ron
 
Where do you want to print to? The form, or the printer? Or something else? If the form, just say Print whatever. For the default printer, just say Printer.Print whatever.

I hate the DataReport object, so I don't know how to use it. :)

HTH

Bob
 
This is an example of what I use in printing data reports. It may not be the best but it works for me. I just call this to print it. It gathers the recordset and prints the report. This example I pass the start and stop date of the query.

Public Sub PRINTTOTALREPORT(mystartdate As Date, myenddate As Date)

On Error GoTo errorhandler

'-- PRINT THE TOTALS REPORT

'-- GET THE REPORT DATA
Dim conTotal As New ADODB.Connection
Dim comTotal As New ADODB.Command
Dim rstTotal As New ADODB.Recordset

With conTotal
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DATABASENAMEHERE;Data Source=DATABASESERVERNAMEHERE"
.CursorLocation = adUseClient
.Open
End With

With comTotal
.ActiveConnection = conTotal
.CommandType = adCmdText
.CommandText = "SQL STATEMENT HERE"
End With

Set rstTotal = comTotal.Execute

'-- IF NO MATCHES
If rstTotal.RecordCount = 0 Then
MsgBox ("No data was found for your request. No report will be generated."), vbOKOnly, "No data matches"
Exit Sub
End If

'-------------------------------------------------------------------------------
'-- MISC DETAILS SECTION OF THE REPORT
'-------------------------------------------------------------------------------

'-- REPORTS ORIENTATION AND MARGINS
rptDepartmenttotal.LeftMargin = 50
rptDepartmenttotal.RightMargin = 50

'-- ANY LABELS GO HERE
rptDepartmenttotal.Sections(1).Controls("label3").Caption = mystartdate & " - " & myenddate

'-- REPORT'S DATA SOURCE
With rptDepartmenttotal
Set .DataSource = rstTotal
End With
rptDepartmenttotal.Refresh

'-- PRINT THE REPORT
rptDepartmenttotal.Show

Exit Sub
errorhandler:
MsgBox ("The program has generated an error. An error report has been sent."), vbExclamation, "Error"

End Sub


 
shannanl, I may hate the DataReport object, but your code does have the enormous advantage of working. :)

Bob
 
I was about try the above code but here is something I still don't know. I am use MS Access to create my database (dbrepair). What do I put in Initial Catalog? is dbrepair or dbrepair.mdb.
I have know idea what to put in Data Source?
My data report name is rptWorkOrder do I need to put any infromation in it(ie rptTextbox,DataSource or DataMember)?


With conTotal
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=WHAT DO I PUT HERE;Data Source= WHAT DO I PUT HERE"
.CursorLocation = adUseClient
.Open
End With



Any help will be Greatly Appreciated

Ron
 
raja130

this is for SQL server. Take a look here for connection strings concerning M$-Access.
 
Thanks Guys I think have it work now!!
:-D
 
I want to search a table for records between two dates and then print the result of the search.I can not make SQL statement for search and display result
 
I'd suggest that you put this on a new thread, since it's not really related to the original. You're asking how to make a SQL statement, not how to print.

You might also want to ask the question in the appropriate SQL column. Are you using SQL Server or Access, for example? You haven't said. There's a separate column for each.

You might want also to look at faq-2244.

HTH,

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top