Solved

printing a form in visual basic 6

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

685 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