VB icon

PrintGrid

Email
Submitted on: 1/1/2015 11:53:00 PM
By: Adam Abas (from psc cd)  
Level: Not Given
User Rating: By 3 Users
Compatibility: VB 5.0, VB 6.0
Views: 1527
 
     To Print DataBase Grid Control as a quick report without buying an expensive tools.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :PrintGrid
'**************************************
	Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
	
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: PrintGrid
' Description:To Print DataBase Grid Control as a quick report 
without buying an expensive tools.
' By: Adam Abas (from psc cd)
'
' Inputs:Data Base Control, Data Base Grid Control
'
' Returns:DBGrid Record source as a Text File with adjusted Columns
 Width.
'
' Assumes:How he,she use a data & dbgrid control in VB application.
'
' Side Effects:No Idea, only when you increase number of columns the 
processing is be slower.
'**************************************

Please,If you do any changes let me know as a feed back.
If you like to have a .OCX as an Activex Email me, free no charge
but no source code. 
Private Function PrintGd(ByVal GridToPrint As DBGrid, ByVal MyRecordset As Recordset) As Long
Dim x, v, b
Dim Putit As String
Dim Myrec
Dim MyField
Dim TCapion
Dim Mydash
 Screen.MousePointer = 11
 
 Open "C:\Printed.txt" For Output As #2
 Putit = ""
 Mydash = "-"
 
 For b = 0 To GridToPrint.Columns.Count - 1
Myrec = ""
MyField = ""
x = GridToPrint.Columns(b).Width
x = x / 100
For v = 1 To x
Mydash = Mydash + "-"
 If Mid(GridToPrint.Columns(b).Caption, v, 1) = "" Then
Myrec = Chr(32)
 Else
Myrec = Mid(GridToPrint.Columns(b).Caption, v, 1)
 End If
MyField = MyField & Myrec
Next v
 Putit = Putit & Chr(9) & MyField
 DoEvents
 '
 Next b
 Print #2, " No" & Putit
 Print #2, Mydash
Close #2
 
Dim Colcap
Dim Toprint
Open "C:\Printed.txt" For Append As #1
MyRecordset.MoveFirst
Dim Nox
Do While Not MyRecordset.EOF
Putit = ""
Nox = Nox + 1
For b = 0 To GridToPrint.Columns.Count - 1
If GridToPrint.Columns(b).Visible = True Then
Myrec = ""
MyField = ""
x = GridToPrint.Columns(b).Width
x = x / 100
For v = 1 To x
DoEvents
 If Mid(GridToPrint.Columns(b).Text, v, 1) = "" Then
Myrec = Chr(32) 'x
 Else
Myrec = Mid(GridToPrint.Columns(b).Text, v, 1)
 End If
 MyField = MyField & Myrec
Next v
DoEvents
Putit = Putit & Chr(9) & MyField
 Else
 End If
 
 Next b
 Print #1, Format(Nox, "@@@") & Putit
MyRecordset.MoveNext
Loop
 
Close #1
Me.Refresh
Dim RetVal As Long
RetVal = ShellExecute(Me.hwnd, _
 vbNullString, "C:\Printed.Txt", vbNullString, "c:\", SW_SHOWNORMAL)
Screen.MousePointer = 0
End Function
Private Sub Command1_Click()
Dim x
x = PrintGd(DBGrid1, Data1.Recordset)
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.