Solved

printing a form in visual basic 6

Posted on 2007-03-18
5
1,792 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 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

14 Experts available now in Live!

Get 1:1 Help Now