473,416 Members | 1,496 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,416 software developers and data experts.

Make a Print Function?

Is it hard to make a Print button from a Windows Form that will print a
number of fields from an Access database in a fairly formatted way? How does
this work with the Print Dialoges and stuff?

I do NOT want to involve Crystal Reports! Been there and never want to do it
again. :)

/Lars

Nov 21 '05 #1
2 3990
"Lars Netzel" <ui****@adf.se> schrieb:
Is it hard to make a Print button from a Windows Form that will print a
number of fields from an Access database in a fairly formatted way? How
does this work with the Print Dialoges and stuff?


The .NET Framework doesn't provide built-in support for easy printing of
tables. You will have to use 'PrintDocument' et al. to print the tables.

If you were using SQL Server as DBMS, you could use SQL Server Reporting
Services (<URL:http://www.microsoft.com/sql/reporting/>).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2
If you can put the fields in question into a report, the printing is fairly
simple. You will need to add a reference to Interop.Access (Microsoft
Access 9.0 Object Library) and possibly Interop.Microsoft.Office.Core
(Microsoft Office 10.0 Object Library). The versions may vary depending on
what you have installed. This function will print any report saved in the
access database, with any where clause. The limitation is you have to
define the report ahead of time and cannot select the fields on the fly.

There is another option for printing a list of fields, although it is rather
indirect. Create a datagrid and populate it with the query you want.
Select all the rows in the datagrid and copy and paste them into Excel.
This can be done manually if you want the user to have to highlight and
copy/paste. You can also just select the query into excel if you want to
put the code together... Somewhere in this newsgroup is an example of
pupulating an excel spreadsheet with a query, you will find it posted as
"Error Exporting to Excel". I wold post the link but I havent figured out
how to link to a newsgroup yet.

Public Shared Sub PrintReport(ByVal strReportName As String, ByVal
strWhereClause As String)

'************************************************* **********************
' Public method
' opens access database and prints reports

'************************************************* **********************
'set the cursor to show we are working
Windows.Forms.Cursor.Current = Cursors.WaitCursor
Dim strDBPath = "C:\temp\MyAccessDatabase.mdb"
Dim oAccess As Access.Application
' Start a new instance of Access for Automation:
oAccess = New Access.ApplicationClass
' Open a database, not in exclusive mode:
oAccess.OpenCurrentDatabase(filepath:=strDBPath, Exclusive:=False)
' Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:=strReportName ,
View:=Access.AcView.acViewNormal, WhereCondition:=strWhereClause)
oAccess.CloseCurrentDatabase()
'set the cursor to nomral when done
Windows.Forms.Cursor.Current = Cursors.Default
MsgBox("Report sent to printer.")
End Sub
"Lars Netzel" <ui****@adf.se> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Is it hard to make a Print button from a Windows Form that will print a
number of fields from an Access database in a fairly formatted way? How does this work with the Print Dialoges and stuff?

I do NOT want to involve Crystal Reports! Been there and never want to do it again. :)

/Lars

Nov 21 '05 #3

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

Similar topics

28
by: The Eternal Squire | last post by:
PEP: 336 Title: Make None Callable Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/11/03 16:58:30 $ Author: Andrew McClelland Status: Draft Type: Standards Track Content-Type: text/plain...
7
by: Lowell Kirsh | last post by:
I have a script which I use to find all duplicates of files within a given directory and all its subdirectories. It seems like it's longer than it needs to be but I can't figure out how to shorten...
19
by: pkilambi | last post by:
I wrote this function which does the following: after readling lines from file.It splits and finds the word occurences through a hash table...for some reason this is quite slow..can some one...
10
by: Nicolas Fleury | last post by:
Hi everyone, I was wondering if it would make sense to make staticmethod objects callable, so that the following code would work: class A: @staticmethod def foo(): pass bar = foo() I...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
3
by: Terry Hancock | last post by:
I still run into my own ignorance a lot with unicode in Python. Is it possible to define some combination of __repr__, __str__, and/or __unicode__ so that the unicode() wrapper isn't necessary...
2
by: mike | last post by:
Hello, I'm trying to write a function to return submatches. I want to do this because I want to run a match on matches of matches of yet other matches, so it seemed to me it would be easier to...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.