Solved

printing a form in visual basic 6

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Message Logon Windows 2012 R2 Server 16 29
VB Script: restart service function 30 39
Restart service script 5 14
Fastest way to find and count same items VB6 16 26
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 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