Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Print/Save DataGrid


I have information in a DataGrid (in VB6) that I need to be able to print or save...not necessarily both. I've tried printing the form, but if there is a lot of information, only the information visible is printed...unless I scroll down and print the form again until all info. is printed.I hope this makes sense....any help will be greatly appreciated.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Save , Print?
How do you write code to "Save/Save As " something in your program like a multiline text box's content or something? How do you print to a printer? I have no idea about where to start?!!! Any suggestions

Save Datagrid Row
Is there a way to save a datagrid row without having to click another record? What is happening is that the last row that I make changes to is not being updated because I do not click the next/another row for data entry. I have tried resetting a bookmark to the same row after the row is updated but this did not work. Thanks for any advice on this!

Save And Print Windows
hi guys,

in my assignment i have this form which the user fills out and chen they click enter data, it puts all their data into a letter.

how would i make it so that when a save button is pressed, or a print button for that matter, in the form it opens the save/print window so they can chose where to save it...

thanks guys

OLE Excel Save,print
Hi,

I have made a Form which contains one OLE object.
OLE object treats an excel file (embed). I can eg. edit, change,.... this excel file over OLE object but i can't save it like *.xls file.

I can save it like ole object but it isn't good for me:


Dim FileNum As Integer

CommonDialog1.ShowSave


FILE_NAME = CommonDialog1.FileName

If FILE_NAME <> "" Then

FileNum = FreeFile

Open FILE_NAME For Binary As #FileNum

OLE1.FileNumber = FileNum
OLE1.SaveToFile FileNum

Close #FileNum

End If

How could I save like excel file and not OLE object...???
How could I print this OLE object without forms, button.... only the excel sheet...???

Could you send me examples???

Thanks!!!

Print Listview Save As
Every time I want to print the listview, I got the common dialog save as.. How I can modify the the common dialog? I want to put the title of the common dialog.

The common dialog point me at my document folder. How I can point the save as common dialog to save the document at the specific path location?


Code:

For i = 1 To ListView4.ListItems.Count
Printer.Print Tab(5); ListView4.ListItems(i); _
Tab(25); ListView4.ListItems(i).ListSubItems(1); _
Tab(45); ListView4.ListItems(i).ListSubItems(2); _
Tab(65); ListView4.ListItems(i).ListSubItems(3); _
Tab(85); ListView4.ListItems(i).ListSubItems(4); _
Tab(105); ListView4.ListItems(i).ListSubItems(5); _
Tab(125); ListView4.ListItems(i).ListSubItems(6)
Next

Printer.EndDoc
End If

SAVE And PRINT Functions
Can anyone help me with the code for "save" and "print" with a text box? I need it to be saved as a *.txt file and if you know how to make it print, you are the man!

thanx
empty words

Save And Print Functions (help Me !!!!)
i need to know how to do save and print functions with a REGULAR(not rich) textbox. i have some code for both.. but it doesn't work.. can you help me?? i can show you the code if you want to see it.

thanx
empty words

How To Not Print Or Save In Excel
Hi all.

I would like to know how can I write some VBA that stops Excel from printing a sheet or saving the workbook unless certain criteria are met. For example, I want to prevent a sheet from printing or being saved if certain cells don't have any information in them.

Thanks.

Save And Print Graph
How can I save and print a graph plotted using MSChart?
Any help would be much appreciated!
-LearnerVB

Print Datagrid
Is there a way to print datagrid content ?
Does anybody know w good website where i could find information about VB printing ??
Thanks 4 your help
BART

How To Print A DataGrid ?
I want to print my DataGrid. How to do so?

How Can I Print My DataGrid In VB6, Please?
Friends,

How can I print my Datagrid in VB6? I am using MS Access database as backend.

I have downloaded the file DataGridPrinter_src.zip from the following link. But it doesn't work. Any help please!

http://www.vbforums.com/showthread.php?t=356115

How To Print Out A Datagrid
Hello,
Is it possible to print out a datagrid directly ? Or how may I create table and print out it ? Thanks

Datagrid Print
I need for help
i have data in datagrid and i wont to print only the data how i can do that (i need a method or somthing else)
thank you!!!

How To Print A Datagrid Help Pls
Sorry - newbie question:


How does one print the contents of a datagrid.

Thanks in advance

Print A DataGrid
Does anyone have a routine that will allow me to output the contents of the datagrid?

The datagrid is connected to an Access Database so I can look at the possibility of adding the SQL statement for the grid as a query within Access and then printing that.

OR

I could print the data directly out of the grid?

What would you suggest and do you have a routine that might do this?

Regards

Chris

Print Datagrid
I would like to print the datagrid located on a form which is connected to an ADO control.

I want it to print basically the same way as it appears on the screen, with field names, rows and columns. The information to be printed will change because it is based on a query. For this reason I think a loop is required but I am still unsure of the process in which to print.

Any help is great!!!

Thanks..
Kim

Print Datagrid
i have a form that after dates are entered into two textboxes and a button is click a datagrid appears and is filled with data.
I have three buttons PrintPreview, PrintSetUp, and Print. I cant get print preview to show the datagrid. WHY?
I am not going to by something that I can code myself. Also the reason I am posting this question again (others have posted it.) is because the answers are not satifactory. code follows. thanks in advance.

Code:
Private Sub PrintPreview()
        Dim ppd As New PrintPreviewDialog
        Try
            ppd.Document = pdoc
            ppd.ShowDialog()
        Catch ex As Exception
            MessageBox.Show("An Error occurred while trying to load the " & _
            "document for Print Preview. make sure you currently have " & _
            "access to a printer. A prnter must be connected and " & _
            "accesable for Print Preview to work.", Me.Text, _
        MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


Code:
Private Sub PrintGrid()
        Dim dialog As New PrintDialog
        dialog.Document = pdoc
        If dialog.ShowDialog = DialogResult.OK Then
            pdoc.Print()
        End If


Code:
Private Sub PrintSetUp()

End Sub


Code:
Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
        Handles pdoc.PrintPage

        Static intCurrentChar As Int32
        Dim font As New Font("Microsoft Sans Serif", 24)

        Dim IntPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
        With pdoc.DefaultPageSettings
            IntPrintAreaHeight = .PaperSize.Height = .Margins.Top - .Margins.Bottom
            intPrintAreaWidth = .PaperSize.Width = .Margins.Left - .Margins.Right
            marginLeft = .Margins.Left ' X coordinate
            marginTop = .Margins.Top ' Y coordinate
        End With

        If pdoc.DefaultPageSettings.Landscape Then
            Dim intTemp As Int32
            intTemp = IntPrintAreaHeight
            IntPrintAreaHeight = intPrintAreaWidth
            intPrintAreaWidth = intTemp
        End If

        Dim intLineCount As Int32 = CInt(IntPrintAreaHeight / font.Height)
        Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, _
            intPrintAreaWidth, IntPrintAreaHeight)
        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
        Dim intLinesFilled, intCharsFitted As Int32
        e.Graphics.MeasureString(Mid(DataGrid1.Text, intCurrentChar + 1), font, _
            New SizeF(intPrintAreaWidth, IntPrintAreaHeight), fmt, _
            intCharsFitted, intLinesFilled)
        e.Graphics.DrawString(Mid(DataGrid1.Text, intCurrentChar + 1), font, _
            Brushes.Black, rectPrintingArea, fmt)

        intCurrentChar += intCharsFitted

        If intCurrentChar < DataGrid1.Text.Length Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            intCurrentChar = 0
        End If

    End Sub


Code:
Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintPreview.Click
        PrintPreview()

End Sub

Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        PrintGrid()

End Sub

Private Sub btnPrintSetUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrintSetUp.Click
        PrintSetUp()
    End Sub




Edited by - bprego on 1/14/2004 10:54:02 AM

Print ADO DataGrid
Does anyone know the easiest way to print the contents of a DataGrid filled with records from an Access database connected by Adodc? DAVE

Print DataGrid
How to print the contents of DataGrid control directly?

Thks,
hewang@hotmail.com

How To Print Datagrid Only?
Private Sub cmdPrint_Click()
Dim BeginPage, EndPage, NumCopies, Orientation, i
'Set Cancel to true
CommonDialog1.CancelError = True
On Error GoTo Errhandler
'Display the print dialog box
CommonDialog1.ShowPrinter
'Get user-selected values from the dialog box
BeginPage = CommonDialog1.FromPage
EndPage = CommonDialog1.ToPage
NumCopies = CommonDialog1.Orientation

For i = 1 To NumCopies
'put codes here to send data to your printer
' something.PrintForm
Me.DataGrid1.Print
==> can i do this if i want to print the datagrid only?the size is
==>stagnant or can i just set the coordinates on the form so the ==>printer can just print the area of datagrid?
==>if yes, how do i go about it?
Next
Exit Sub
Errhandler:
'user press cancel button
Exit Sub

End Sub

How To Save Info In Datagrid
hai

I am using a datagrid in vb6.My back end is mysql.I would like to know as how to save the info displaying in datagrid to be saved in a tabel in my database

How To Save From Datagrid To Database?
how do i save updated records from datagrid to database...
at the moment i can only add 1 new record at a time, but can't update the editted records in the datagrid to database. wat bout deleting records from datagrid?

the following r part of my codes:-

Private Sub cmdRekod_Click() ***to save records in database***

Set rs = GetRs("Select * from TablePengumuman where NoPek='" & Replace(lblNoPek.Caption, "'", "''") & "'")
Set DataGrid1.DataSource = rs

With rs
.ActiveConnection = Cnn.ConnectionString
.UpdateBatch ****cannot update editted record in the
datagrid to database****
End With

CleanUP:
On Error Resume Next
If Not rs Is Nothing Then
Set rs.ActiveConnection = Nothing
Set rs = Nothing
End If

End Sub


Private Function GetRs(ByVal strSql As String) As ADODB.Recordset
'To fill the grid, you fill a recordset
'then you assign it to the grid source
Dim tmpRs As ADODB.Recordset
Set tmpRs = New ADODB.Recordset

With tmpRs
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open strSql, Cnn
End With

Set GetRs = tmpRs

End Function

***how come no new row is added after i press enter on the last row to start a new row?i've oredi set allowaddNew to true ***

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
cmdRekod.Enabled = True
DataGrid1.Columns(0).Visible = False

'the grid is updatable, and it lets you add new records
'here we need to provvide a refresh if something changed enough
If Not IsEmpty(LastRow) Then
If DataGrid1.Text <> "" Then
cmdRekod.Enabled = True
End If
End If
End Sub

How Do I Print And Save Only The First Page Of A Document?
Sounds like a silly question... I know. Basically, if a value in my Access database is less than 2, I need to delete the second page of a word document and then save and print it. It should look something like this:

If x < 2 then

objWord.ActiveDocument.DeleteSecondPage

end if

objWord.ActiveDocument.PrintOut (acPrintAll)
objWord.ActiveDocument.SaveAs....

Nothing complicated, I just can't figure out the commands. Any help would be greatly appreciated.

How Do I Save &amp; Print An Excel Graph
I have a project that has an excel graph but i need to be able to save this graph. i think i could print it then but i don'e reall y know how to go about saving it. Any help would be graetly appreciated...

Save Sheet &amp; Print Automaticly
Hi...

I created an invoice sheet with all the client information I need, and also with all the details of what he ordered.

Lets call my client "George Lucas" and my sheet "invoice.xls".

All of the areas in the sheet that does not need to be edited, are protected.

So what I was to di is this!

When filled with the information of my client, I want to create a button that when clicked, it will automaticly save the sheet to a folder on my desktop with the name of the client entered in the name field, and will print the sheet afterward. Also, I want it to close the document and leave my "invoice.xls" all blank after that.

So when I click the button on the sheet somewhere, it will save my sheet on my desktop in a folder named "sheet", abd the xls file will be named for that matter "george lucas.xls", and it will also print the invoice to my printer, and close. And when I will open my "invoice.xls" file for another client, all fields will be blank...


Hope I'm clear enough...

I'm having a lot of trouble trying to make it with macros...

Hope someone can help me out !

Best regards

Mat
Edit by italkid: Removed e-mail address > asking for offline help defeats the purpose of a public forum...

Problem W/ CommonDialog For Save And Print
Hello all,
Im having a very annoying problem that I just cannot figure out. I hope the experts here would easily see through it.
I have two commands using CommonDialog: one to Save and the other to Print.
When the Save Dialog shows up and I cancel, it works. Similarly, when the Print Dialog shows up and I cancel it works as well.

However, if Id like to save a file that already exists, a message prompt asks if Id like to replace the file.
The problem starts when I chose No to file replacement and right after I click on Print, then the Print Dialog doesnt show up and the printer starts printing without my permission.
Here are the codes for both Save and Print:

Code:
Sub printfile()
Dim BeginPage, EndPage, NumCopies, Orientation, i
Dim defaultname As String
' Set Cancel to True.
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Display the Print dialog box.
CommonDialog1.ShowPrinter
' Get user-selected values from the dialog box.
BeginPage = CommonDialog1.FromPage
EndPage = CommonDialog1.ToPage
NumCopies = CommonDialog1.Copies
Orientation = CommonDialog1.Orientation
For i = 1 To NumCopies
'Print the complete report
Printer.Print txtBox
Next
Printer.EndDoc
Exit Sub
ErrHandler:
' User pressed Cancel button.
Exit Sub
End Sub
'-----------------------------------

Function GetFileName(Filename As Variant)
On Error Resume Next
CommonDialog1.Filename = Filename
CommonDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*" 'sets the file types
CommonDialog1.ShowSave


'Checking if the file already exists
Dim mypath
mypath = CurDir 'Show the directory user has chosen to save the file

If Dir$(CommonDialog1.Filename) <> "" Then
'Ask the user if file should be replaced
If MsgBox(mypath & "" & Filename & " already exists." & vbCrLf & "Do you want to replace it?", _
vbExclamation + vbYesNo, "Replace Report") = vbNo Then
Exit Function 'Not replaced
End If
End If

If Err.Number <> 32755 Then 'if the user has not chosen to cancel
GetFileName = CommonDialog1.Filename
Else 'user chose cancel
GetFileName = ""
End If
End Function
'-----------------------

Sub SaveFileAs(Filename)
On Error Resume Next
Dim content As String

'Open the file
Open Filename For Output As #1
'Place the contents of the report into a variable
content = txtBox
'Display the hourglass mouse pointer
Screen.MousePointer = 11
'Write to the saved file
Print #1, content
Close #1
'Reset the mouse pointer
Screen.MousePointer = 0
End Sub

Any idea why?

All help, ideas, suggestions are very welcomed!

Save/print Controls From A Picturebox
Hey,

I'm using a picturebox as a container for several controls (like mschart, dtpicker, ...).
Now I want to save and print these controls. Does anyone have an idea how to do this?

I tried to copy the whole pictureBox to a richtextbox and print this one. But the problem was that not the whole picturebox is visible (you have to scroll) and so only the visible part is copied.

Ben

Print Screen / Save As Utility?
Hello,
I am looking for a utility I can add to my code for screen capturing to print active windows and also capturing to save as .bmp (or other). Does anyone have any good suggestions?
Thanks.

Print, Save And Copy To ClipBoard
I have a program which for ever letter you type into a text box, it puts an image into a picture box using BitBlt. I dont know how to print, save or copy the Picture to a clipboard (So you can use it in other programs)

The picturebox is called: pixExport
And the menu for save is: mnuSave
" "Print is: mnuPrint
" "Copy is: mnuCopy

Could any one kindly give me the code please?

How To Take Screen Print And Save To A File In Vb6?
Hi

I need to take a screen print or screen shot and then i need to save that screen print to a .bmp file. how can we do this using VB 6?

thanks
srinivas

Print To File - Save Location And Name
Hello. Please help me to print to file from code set the path and the name of the new file also from the code. I can user either vb6 or vb.net

Mschart -&gt; Save To Image -&gt; Print
I got a mschart that I generated and now I need to save it to an imagefile and then be able to print that image (or mschart).

Please place it under two buttons
One button that do the save to a file (SaveDialogWindow)
and one button that does the print fileimage or print the MSChart
Thanks alot for the help.

//Martin Andersson

Print Or Save Form Or Graph
Is there a way to print a graph?

Or Save a graph as an image or do a print screen or something?

thanks

PictureBox.Print, Then Save The Picture As BMP
I am writing an application that prints text into a picture box. Kind of a virtual print thing. I want to create a bitmap of the new contents of the picture box. How would I go about doing this?

I have been wrapped around BitBlt all day long, and hopefully someone can shed some light on why I can get graphics into a picture box but not back out. The text has to be dynamically inserted, either through DrawText Api with the Rectangle Concept or Through PictureBox1.Print "Blah Blah Blah".

This link in the forum approaches what I am trying to do, however doesn't quite nail it.

Link to BitBlt Desktop Capture

Thank in Advance.

Matt

Access Listbox Print/save
I have a multiple column listbox(List1) which displays the results of a search. I want to be able to either save the whole contents of the list box to a text file or print it out. I have tried the following code:

Dim X
Open "C:MyFile.txt"
for Output as #1
for X = 0 to List1.ListCount - 1
print #1, List1.List(X)
next X
Close #1




But the '.List'brings up an error for some reason . Is it maybe something to do with the multiple columns?. If so is there anyway to get it to save contents with multiple columns? If anyone colud help it would be greatly appreciated.

Thanks,
Oliver

Print DataGrid In VBA Trouble
I have a datagrid that is being populated from an Access database from a macro running in AutoCAD 2004 VBA. I am able to bind the datagrid to an ADO recordset and I am trying to use loquin's PrintDG module from the code library to print the datagrid itself. But I keep getting Object Variable not set errors and Automation Errors.

I have removed the ability to change margin settings, print the header, lines, etc. and hardcoded all of those values. The connection to the database is still open and the recordset is still open.

I can see the Printer object in the object browser, actually there are 2 printer objects in the browser, one for VB and one for Access.

Am I trying to do something that VBA cannot handle, or is there something else I am missing?

Here is the 1st portion of the code that is causing problems.

Code:
' Set Orientation
OldOrientation = Printer.Orientation '<---Error here "Object Variable or With 'block variable not set
If Portrait Then
Printer.Orientation = PrintPortrait
Else
Printer.Orientation = PrintLandscape
End If
'15840 12240
' Determine page breaks
' calculate print area (PrintWidth, PrintHeight) & Margins
TopMargin = Top * TwipsPerInch
BottomMargin = Printer.Height - (Bottom * TwipsPerInch) ' Relative to Left edge
LeftMargin = Left * TwipsPerInch
RightMargin = Printer.Width - (Right * TwipsPerInch) ' relative to Top Edge
PrintHeight = BottomMargin - TopMargin
PrintWidth = RightMargin - LeftMargin

If I change the code to

Code:
' Set Orientation
OldOrientation = VB.Printer.Orientation'<--Add the VB Class before the Printer
'object I get "Automation Error The object invoked has disconnected from its clients"
If Portrait Then
VB.Printer.Orientation = PrintPortrait
Else
VB.Printer.Orientation = PrintLandscape
End If
'15840 12240
' Determine page breaks
' calculate print area (PrintWidth, PrintHeight) & Margins
TopMargin = Top * TwipsPerInch
BottomMargin = Printer.Height - (Bottom * TwipsPerInch) ' Relative to Left edge
LeftMargin = Left * TwipsPerInch
RightMargin = Printer.Width - (Right * TwipsPerInch) ' relative to Top Edge
PrintHeight = BottomMargin - TopMargin
PrintWidth = RightMargin - LeftMargin
After the error Automation error above VBA and AutoCAD expierience a fatal error and close.

I can provide more code or more description if needed. Thank you in advance for your help.

Bart

HOw To Print A Complete DataGrid ??
Hi,

i tried this :

Private Sub PrintList()
Dim TempFile As String

TempFile = App.Path & "Temp.bmp"

SavePicture DataGrid1.CaptureImage, TempFile

Printer.Orientation = vbPRORLandscape
Printer.PaintPicture LoadPicture(TempFile), 0, 0
Printer.EndDoc
Kill TempFile

MsgBox "The grid has been printed."

End Sub


But i only got a cut of the DataGrid, not the whole. Does anyone know how to do so ??


Thanks

How To Print DataGrid Values?
In VB.NET there is this PrintDocument control that will do the job, but unfortunately I am using Visual BAsic 6.0 Anyone know the vb code to print datagrid values by not using shareware .dll to do that? (cos I can't register .dll in school

Print Datagrid Data
Im using an ADODC to fill data on a Datagrid.I wanted to print (by a printer) the data displayed on the datagrid.I tried to look for any print method for any of the two controls im using but i couldn't find one.Im thinking of transferring the data into a rich textbox control since the control has a print property.bt is there another and easier way to print the data?Thank you very much.

Print The Contents Of A DataGrid
OK, so my SQL statements are great and my software has a cool feature like a query builder on it. I put a data grid and two combo boxes for the Sort Items By... then By. Really nice... my problem is, how do i print the contents of the DataGrid? I would like to add a button that says PRINT at the bottom of the Grid.

Do I...

a) Get the data FROM the Grid and print it.
b) Print from the recordset.

BTW, am using the Data Environment and Data Report.

Any input will help. THanks in advance.

Cheers!

Datagrid Print Problem!
datagrid have a lot of tables, when i try to print, but it all print out, how can I print only by I select that table?

urgent need solve.

thanks, guys!

Print Datagrid, Any Ideas?
Which is the best way you think to print a DataGrid? Do i have to install any activex control or will it go with plain code?
Thank you all

Print Next Line Of A Datagrid
I have a form "frmcashregister" and a datagrid "dgdetail", a function in module,
I use print method to print a dgdetail it work fine using the following function:

VB Code:
Public Function Cprint()Printer.PrintPrinter.Print "House Value"; Spc(10); Date & " " & Time; Spc(10); frmcashregister.txtuser.Text; Spc(10); frmcashregister.txtnota.TextPrinter.PrintPrinter.Print frmcashregister.dgdetail.Columns(1); Spc(5); frmcashregister.dgdetail.Columns(3); Spc(5); frmcashregister.dgdetail.Columns(4)Printer.NewPagePrinter.EndDocEnd Function

The dgdetail can have many line
The problem is, it only print the first line of dgdetail, How do I print next line?

Anyone can help is very much appreciated

How To Print Data From The Datagrid?
I used adodc to display data on the datagrid, but my data seem to be so many rows for the user to check. So i really want to make the data from the datagrid printable. I tried to looked up on the adodc properties and the datagrid properties but found nothing useful. Can anyone here help me ?

Print A Datagrid Control
Hi All,
How can I send the contents of a Datagrid to a printer on LPT1 with the table names in order and the rows and columns tabulated correctly.
Cheers
R

Anybody Know How To Print DataGrid Contents?
Anybody know of a way to print the contents of a DataGrid, including rows which are not in the visible area?

How To Print Datagrid With Adoc
Hi


How to Print datagrid without Adoc

How To Print Record From Datagrid?
Hi,
I have an application in which i have one datagrid and i want to print the record which i select from datagrid. how can i do this??
i have serial no in datagrid wna d want to print record by seril no.

please help me




pratik meha

Copyright 2005-08 www.BigResource.com, All rights reserved