473,320 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

First Report in VB2005 - Print Preview

Hi all,
Need i simple example on how print/preview data from a database.
I already have some code but I am lost because the preview does not create
multiple pages and only shows the first page and the printing goes over the
margins of the page. My problem is that I cannot figure out how to control
new page when page is getting full. Another problem is that I would like to
have a common place to set headers and footers to be printed every time a
new page is sent.

I would like to have a little code sample even with just printing lines.

This is part of the code that I am using with MySQL database just going thru
some records:

While datareader.Read()

e.Graphics.DrawString(datareader("upc").ToString, sfont, Brushes.Black,
lblpos(0) + 0.5, YPosition)

e.Graphics.DrawString(datareader("description").To String, sfont,
Brushes.Black, lblpos(1) + 0.5, YPosition)

e.Graphics.DrawString(datareader("onhand").ToStrin g, sfont, Brushes.Black,
lblpos(2) + 0.5, YPosition)

e.Graphics.DrawString(datareader("min").ToString, sfont, Brushes.Black,
lblpos(3) + 0.5, YPosition)

e.Graphics.DrawString(datareader("cost").ToString, sfont, Brushes.Black,
lblpos(4) + 0.5, YPosition)

e.Graphics.DrawString(datareader("price").ToString , sfont, Brushes.Black,
lblpos(5) + 0.5, YPosition)

CountLine += 1

YPosition = TopMargin + (CountLine * myFont.GetHeight(e.Graphics))

Console.WriteLine(">>>" & YPosition)

If CountLine = 20 Then

e.HasMorePages = False

CountLine = 1

Else

e.HasMorePages = True

End If

End While

datareader.Close()

Some of the code has been omitted.

Thanks,

-hb


Aug 29 '06 #1
1 1549
Hector M Banda wrote:
I would like to have a little code sample even with just printing lines.

This is part of the code that I am using with MySQL database just going thru
some records:

While datareader.Read()

e.Graphics.DrawString(datareader("upc").ToString, sfont, Brushes.Black,
lblpos(0) + 0.5, YPosition)

CountLine += 1

YPosition = TopMargin + (CountLine * myFont.GetHeight(e.Graphics))

Console.WriteLine(">>>" & YPosition)

If CountLine = 20 Then

e.HasMorePages = False

CountLine = 1

Else

e.HasMorePages = True

End If

End While

datareader.Close()

Some of the code has been omitted.
When you set HasMorePages = True, all that does is tell the printing
engine to call the print page event again. Normallty, when you set
HasMorePages to true, you should exit the method. You need to keep
track of where you are in the datareader so that when the PrintPage
event is fired again, you pick up printing from that point. The
DataReader should be created *outside* of the PrintPage method.

When you reach the end of the page you are currently drawing on, if you
still have more to print, you should set HasMorePages to true and then
exit the PrintPage event. It will get fired again and you can pick up
where you left off.

Aug 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ray | last post by:
I am trying to create an icon so that when someone reachs the end of a report page they can preview and print. Does anyone have any suggestions aboutte best way to do this. I can crate the...
1
by: Evets Htims | last post by:
This is Access 2003. Have a report that includes three subreports stacked on top of one another (they display order items). In the report On Open I build a recordset (to get a value from a foreign...
5
by: nick_faye | last post by:
Hi, I am still a newbie to VB and using MS Access 2000. I am currently trying to provide a preview of reports before printing them. My program is simple: AC.DoCmd.OpenReport "MyReport",...
4
by: Gary | last post by:
Hello, I'm hoping someone can shed some light on why my report does not output the same results as shown in preview mode, which is to move the position of a check box based on a field value (see...
1
by: vermutmb | last post by:
I'm totally stuck. When I click on the "Preview" button for a report on the database window, pressing the <ESCAPEkey simply closes the report. But when I use DoCmd.OpenReport with acPreview on a...
15
by: sara | last post by:
I am stuck. I have a report that I use in multiple places, so I call it with varying parameters (using the Where Clause in the code). I preview the report, send it to snap, then close the...
1
by: mailjaneen | last post by:
Hello, can someone help me. I want to display some fields on a report in print preview (i.e. instructions), that I don't want to print to the printer or export to file. I can't seem to find any...
11
by: Gord | last post by:
When I open a certain report, it runs some code that generates the records that will be displayed in that report. This works fine. When I go to print preview the report it appears that the code...
4
by: scubasteve | last post by:
I've developed a product pricing application for a client in AC2007. They enter all the data on the one main form, then click a button to open a printable report in Print Preview. My problem...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.