Solved

printing a form in visual basic 6

Posted on 2007-03-18
5
1,794 Views
Last Modified: 2013-11-26
hello,
i am currently working in visual basic 6 and have developed a database project. Now i want to print a form (information entered by the user in a form) HOW can we print that?
waiting for reply, thanx in anticipation
fa

0
Comment
Question by:fatimao
5 Comments
 
LVL 4

Accepted Solution

by:
cx323 earned 25 total points
ID: 18744930
Private Sub Command1_Click()
On Error Resume Next
Me.PrintForm
End Sub
0
 
LVL 15

Assisted Solution

by:cquinn
cquinn earned 25 total points
ID: 18748985
Add this to a module, then call the Printscreen() subroutine - it will scale the print to fit the paper

Option Explicit

Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const VK_SNAPSHOT As Byte = &H2C

Function Printit(ByVal hDC_Dest, ByVal DestX, ByVal DestY, ByVal DestDevWidth, ByVal DestDevHeight) As Integer
    Dim lHeight As Long
    Clipboard.Clear
    Call keybd_event(VK_SNAPSHOT, 1, 0, 0)
    DoEvents
    lHeight = (Printer.ScaleWidth / Screen.Width) * Screen.Height
    Printer.PaintPicture Clipboard.GetData, 0, 0, Printer.ScaleWidth, lHeight
    Printit = True
End Function

Sub Printscreen()
     
'Dump the current screen to the default printer
Dim r As Integer
DoEvents
' routine to print correctly.
 Printer.ScaleMode = 3

 ' Change MousePointer to an hourglass.
 Screen.MousePointer = vbHourglass

 ' Initialize the printer.
 Printer.Print ""

 ' Copy the image of the screen to the printer.
 r = Printit(Printer.hDC, 0, 0, Printer.ScaleWidth, Printer.ScaleHeight)
 

 ' Display an error if the return value from PrintWindow is zero.
 If Not r Then
    MsgBox "Unable to print the form", vbCritical + vbOKOnly, "Screen Print Failed"
 Else
    Printer.EndDoc
 End If

 Screen.MousePointer = vbDefault
End Sub

0
 

Author Comment

by:fatimao
ID: 18765671
thanks alot for all the help both the methods do work ... but i want to only want to print the information entered by user in grid and text boxes, the printscreen method and me.print() prints the whole form along with the buttons and other controls ...
please further help in this regard

thanx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now