-
Jun 8th, 2005, 09:20 PM
#1
Thread Starter
Lively Member
Printing
Hi guys. I was just wondering if its possible to print a recordset with column lines and rows? Thanks in advance guys.
Last edited by trex; Jun 8th, 2005 at 09:41 PM.
-
Jun 9th, 2005, 12:59 AM
#2
Re: Printing
Load the rs into a flexgrid (with the gridlines you want) along with colums headings, and then print the form that its on.
-
Jun 9th, 2005, 01:18 AM
#3
Re: Printing
Originally Posted by trex
Hi guys. I was just wondering if its possible to print a recordset with column lines and rows? Thanks in advance guys.
Yes it is possible.
It may take time for me to write the code. But here is the general procedure to follow:
1. Use the rs.GetString method to get it into a variable and finally write it to a CSV file.
2. Open this CSV file in an Excel object and do the column formatting, column width, fonts etc. and then print it.
Pradeep
-
Jun 9th, 2005, 01:21 AM
#4
Re: Printing
That's an awful lot of work just to get gridlines, not to mention that it would requre the use of Excel.
-
Jun 9th, 2005, 04:10 AM
#5
Re: Printing
Originally Posted by dglienna
Load the rs into a flexgrid (with the gridlines you want) along with colums headings, and then print the form that its on.
Yea, you need excel...but your method prints a form. How evil. Plus...what happens if there are more records than you can fit on the page? Alas, when printing like this it does not print all rows from the flexgrid, just what you can see.
Woka
-
Jun 9th, 2005, 05:35 AM
#6
Re: Printing
We have a general SUB to print a FLEX GRID - it analyzes the column widths...
Then it looks at the printer. Checks if it would fit at font 8, font 10, landscape, portrait - sees if legal tray is available.
Then asks the user what they want to do - print on legal - stuff like that.
Then it simply loops through the rows and columns and with the PRINTER object and setting .CURRENTX/.CURRENTY it prints the grid.
It's very easy to print lines with PRINTER object as well - using PRINTER.LINE (x,y) - look up the exact format of this in HELP...
-
Jun 9th, 2005, 05:46 AM
#7
Re: Printing
Hi guys. I was just wondering if its possible to print a recordset with column lines and rows?
the answer to this is yes,
there are several ways to do it including some of the ones mentioned above, and also 3rd party tools such as qprinter2 and preview. plus the MS datareport designer
also you can just print to the printer the data and the lines, horizantal and vertical, so that you have control over your own code.
most people will have their own preferences as to which they use
pete
-
Jun 9th, 2005, 05:55 AM
#8
Re: Printing
Sorry my bad, I should have explained more in my post.
To carry on from the 2 above posts you can use the printer object.
VB Code:
Printer.Print "Woof"
Printer.EndDoc
should print "Woof" on a page
You require something like:
VB Code:
Dim adoRec As Recordset
'create recordset from DB
With adoRec
Do While Not .EOF
Printer.Print .Fields("Username").Value
.MoveNext
Loop
.Close
End With
Set adoRec = Nothing
Printer.EndDoc
This would print all usernames to a page.
To print grid lines and different fonts etc then you will need to use code similar to the above, but a little more complicated.
We had some code to print from a listview I think. This was in a job I had 4 years ago.
I'll see if I can dig it out.
Woka
-
Jun 9th, 2005, 05:59 AM
#9
Thread Starter
Lively Member
Re: Printing
Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?
-
Jun 9th, 2005, 06:04 AM
#10
Re: Printing
I use this (or a varation of this) when I need to print a Recordset. You can modify this to include your lines and whatever following szlamany's suggestion. I don't really care about lines as much as margins and different pages, but this should get you started. This assumes the recordset exists already.
VB Code:
Const TOP_MARGIN = 1440
Const LEFT_MARGIN = 1440
Dim BOTTOM_MARGIN As Single
BOTTOM_MARGIN = Printer.ScaleTop + Printer.ScaleHeight - 1440
AdoRs.MoveFirst
Printer.CurrentY = TOP_MARGIN
Do While Not AdoRs.EOF
Printer.CurrentX = LEFT_MARGIN
Printer.Print AdoRs!Field1 & vbTab & Rs!Field2
' See if we have filled the page.
If Printer.CurrentY >= BOTTOM_MARGIN Then
' Start a new page.
Printer.NewPage
Printer.CurrentY = TOP_MARGIN
End If
AdoRs.MoveNext
Loop
AdoRs.Close
Printer.EndDoc
Set AdoRs = Nothing
-
Jun 9th, 2005, 06:09 AM
#11
Re: Printing
Hack is printing one row at a time - with vbTab to move the columns into some kind of placement.
We actually print each cell - one at a time - and increment .CURRENTX to move to the right for each cell.
In order for automatic line advance to not occur - put a ; character at the end of the print statement - such as PRINTER.PRINT RS!COL;
By setting the .CURRENTX/.CURRENTY ourselves it's quite easy to make sure that you have a TWIP position on the paper for the grid-lines to appear in.
-
Jun 9th, 2005, 06:10 AM
#12
Re: Printing
Originally Posted by trex
Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?
.CSV is a file extension for a comma-separated file - one that's easy to import into EXCEL.
I would recommend keeping away from EXCEL to perform this task - you will only be burned by it's poor formatting of dates and numeric values...
-
Jun 9th, 2005, 06:10 AM
#13
Re: Printing
Originally Posted by trex
Hi. hmmm im sorry for this but whats csv file? and how do i print a flex grid without printing the form?
CSV files are Comma Seperated Files and Excel recogizes it easily. But it was just an example. You may use tab seperated file or any other delimiter.
Writing out a CSV file is easy:
VB Code:
Sub RecordsetToCSV(rs as ADODB.Recordset)
Dim m
rs.MoveFirst
m = rsurl.GetString(, , " , ", vbCrLf)
Open App.Path & "\MyFile.csv" For Output As #1
Print #1, m
Close #1
m = ""
End Sub
After this you may open this file in Excel and print it.
Pradeep
Last edited by Pradeep1210; Jun 9th, 2005 at 06:14 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|