-
Re: printing access reports using vb.net
There should be a print to and print from argument of the .Print method. Or how are you invoking the print as of now?
-
Re: printing access reports using vb.net
-
Re: printing access reports using vb.net
this is all my code, maybe that tells you what you need:
Code:
Option Explicit On
Option Strict On
Imports Microsoft.Office.Interop
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnAfdrukken As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnAfdrukken = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'btnAfdrukken
'
Me.btnAfdrukken.Location = New System.Drawing.Point(96, 24)
Me.btnAfdrukken.Name = "btnAfdrukken"
Me.btnAfdrukken.TabIndex = 0
Me.btnAfdrukken.Text = "Afdrukken"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(264, 24)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(680, 502)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.btnAfdrukken)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnAfdrukken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAfdrukken.Click
Dim moApp As Access.Application
Dim acViewPreview As Access.AcView
Try
moApp = DirectCast(GetObject(, "Access.Application"), Access.Application)
Catch ex As Exception
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
Else
MessageBox.Show(ex.Message, "VB/Office Guru™ Access Demo", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
'moApp.Visible = True
moApp.OpenCurrentDatabase("C:\Documents and Settings\Joris\Bureaublad\Nieuwe map\GGIP\BierDatabase.mdb")
moApp.RunCommand(Access.AcCommand.acCmdAppMaximize)
moApp.DoCmd.Maximize()
moApp.DoCmd.SetWarnings(False)
moApp.DoCmd.OpenReport("rptBier", acViewPreview)
moApp.CloseCurrentDatabase()
End Sub
End Class
-
Re: printing access reports using vb.net
Well you are previewing the report so if the user clicks print from the Access toolbar then it will print all pages. If they use the Print... from the File manu then they can designate the pages to print.
-
Re: printing access reports using vb.net
Actually, it's not previewing anything, not even before I added the CloseCurrentDatabase.
It all has to work out of the program, this fatso is too much of a lazy bum to learn how to use access, so I gotta make it in vb for him. So no file menu for me I guess..
-
Re: printing access reports using vb.net
I'm out for today, it's getting kinda late.
I'll see you tomorrow I hope :).
My personal vb hero ^^
-
Re: printing access reports using vb.net
Np.
There are two things more you can do.
One: filter the reportsource query to only produce the final printed recordset needed and then .OpenReport passing the Normal view argument which is print.
Two: call the printout method but that will print all the pages.
-
Re: printing access reports using vb.net
and how do I make that filter?
-
Re: printing access reports using vb.net
Add a where clause to the sql query that is your reportsource.
-
Re: printing access reports using vb.net
I'll see what I can do.
Questions to come later :)
-
Re: printing access reports using vb.net
Ok, maybe in a new thread as its a bit of a different topic. Plus, other members may be more inclined to help in a new thread instead of reading through tweo pages of the original topic.
-
Re: printing access reports using vb.net
Ok, but still in the end thisis what the program is supposed to do, just so we're on the same page.
Start up a self-made program, view the database in datagrids and be able to edit the database (already done).
Be able to search something inside the same program using terms like "bee".
Then the program should search everything which corresponds to *bee*.
Be able to print the record which was looked up by the search function in the form of a report. Or either just be able to view the reports one by one in the program and print one to your own choice out.
Last one: if you click "go back" in a window of the program after you made changes to the database, but didn't click on update there should be a pop-up window asking wether you want to quit, or go back and save the changes.
Ofc if you click go back to save changes, you should go back and be able to save the changes.
This is just what my program has to do in the end. Is it possible?
-
Re: printing access reports using vb.net
Second to last item, if they are to select a record out of the report then it should not be in a report (report records are not selectable in preview mode). Create a secondary form to display the query results and then what ever they check you can pass to the report for printing.
-
Re: printing access reports using vb.net
As long as it all happens inside the program, it's good.
-
Re: printing access reports using vb.net
Em like??
the report corresponding to the record you selected in the datagrid I mean.. not a record out of a report. I'm not that stupid.
-
Re: printing access reports using vb.net
I think its not checkable under the previous Access versions but test it just in case. 2007 you can check a checkbox in a report in preview view.
Ps, didnt mean it that way. ;)
-
Re: printing access reports using vb.net
Well, I'm going to come back at this on monday, after I saw my teacher. She might give a hint.
-
Re: printing access reports using vb.net
Ok, no hints :'(
Is there a way to view the report inside the program?
EVERYTHING HAS TO HAPPEN INSIDE THE PROGRAM, just to stay on the same page ;)
-
Re: printing access reports using vb.net
So you are saying that you can not display Access at all?
-
Re: printing access reports using vb.net
Yes, that's what I'm saying.
I think I got a crap work for school btw, I didn't choose to do this.
-
Re: printing access reports using vb.net
If you can not display Access at all then you can not use any of the code. this was in some of my first posts.
Since you need to show "a" report you need to use something else to display it like just a data grid, data environment report designer, or ???
-
Re: printing access reports using vb.net
I used a grid for my tables, I don't know what's best for reports.
Any idea's?
ps: sorry, thought it was clear everything had to happen inside the program.
-
Re: printing access reports using vb.net
You could print the report directly to a secondary form or use the print preview control dialog.
-
Re: printing access reports using vb.net
Which would be easiest to implement? Because I have to understand what I'm writing here, otherwise it's not very learnful.
-
Re: printing access reports using vb.net
Either one is about the same difficulty, not too easy but in .net
-
Re: printing access reports using vb.net
Ok, then either one is fine, choose which you can explain best to someone like me. I'm off to bed, have to get up at 3.45 tomorrow, night night.
-
Re: printing access reports using vb.net
NOOOOOEEEES my personal vb hero/guru left me!!
-
Re: printing access reports using vb.net
No, I have been out for a while but should be back now.
Try using the printpreview dialog control. There are some examples on the MS site for it. Try a search.
-
Re: printing access reports using vb.net
-
Re: printing access reports using vb.net
Ok, I tried looking, and I couldn't really find any examples which include access except for this one, I put my database in the samples map and replaced every northwind which wasn't in comment into the name of my database, and it doesn't work yet, I know I'll have to change some extra stuff, looking all of that up right now, but still, this code displays acces.
So maybe can you explain about the printpreview control dialog and other stuff?
And my teacher won't answer for the next 2 weeks, it's vacation now that's good :D and bad :( news..
Maybe if you add me on msn it's easier to explain than 40 posts, I know I'm not fast sometimes :o which doesn't make it easier.
Mine is [email protected] if it's ok by you, elseway we'll just use posts, slower but it'll work ;).
-
Re: printing access reports using vb.net
After 3 weeks still no answer, is this thread abbandoned? Right now I've got 4 days left, and I still don't know how to select the exact pages to print from the report. Right now it just prints all, and it's by code (yours). Can you explain me how to do this by the print preview control dialog?
This is the code I used from you btw, not that it matters anymore I think.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim moApp As Access.Application
Dim acViewPreview As Access.AcView
Try
moApp = DirectCast(GetObject(, "Access.Application"), Access.Application)
Catch ex As Exception
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
Else
MessageBox.Show(ex.Message, "VB/Office Guru™ Access Demo", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
moApp.Visible = True
moApp.OpenCurrentDatabase("V:\Users\Frederik\Desktop\Bierdatabase met rapport.mdb")
moApp.RunCommand(Access.AcCommand.acCmdAppMaximize)
moApp.DoCmd.Maximize()
moApp.DoCmd.SetWarnings(False)
moApp.DoCmd.OpenReport("rptBierengoed", acViewPreview)
moApp.CloseCurrentDatabase()
End Sub
-
Re: printing access reports using vb.net
Ok, I'm editing this for resolved, I edited the code a bit more to add a printrange, and now it works like a charm. I'll still have to remove bits and pieces, but this is what I got for now.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim moApp As Access.Application
Dim acViewPreview As Access.AcView
Dim begin As Integer
Dim einde As Integer
begin = CInt(TextBox1.Text) + 1
einde = CInt(TextBox2.Text) + 1
Try
moApp = DirectCast(GetObject(, "Access.Application"), Access.Application)
Catch ex As Exception
If TypeName(moApp) = "Nothing" Then
moApp = DirectCast(CreateObject("Access.Application"), Access.Application)
Else
MessageBox.Show(ex.Message, "VB/Office Guru™ Access Demo", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End Try
moApp.Visible = True
moApp.OpenCurrentDatabase("V:\Users\Frederik\Desktop\Bierdatabase met rapport.mdb")
moApp.RunCommand(Access.AcCommand.acCmdAppMaximize)
moApp.DoCmd.Maximize()
moApp.DoCmd.SetWarnings(False)
moApp.DoCmd.OpenReport(ReportName:="rptBierengoed", _
View:=Access.AcView.acViewPreview)
' Print a report named Sales:
moApp.DoCmd.OpenReport(ReportName:="rptBierengoed", _
View:=Access.AcView.acViewNormal)
moApp.DoCmd.PrintOut(Access.AcPrintRange.acPages, begin, einde, Access.AcPrintQuality.acHigh, 1)
'moApp.DoCmd.OpenReport("rptBierengoed", Access.AcView.acViewPreview)
moApp.CloseCurrentDatabase()
End Sub
The +1 on beginning and ending is because the number 1 report is empty.