473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to print all data from datagrid to printer??

Hi,this is my code for print data to my default printer,but not for all data.

1.How to print all data from datagrid to printer?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command2_Click()
  2.  
  3. Dim RRow As Integer
  4. Dim Colomn1 As Integer
  5.  
  6. DataGrid1.row = 0
  7. DataGrid1.Col = Colomn1
  8. For Colomn1 = 0 To DataGrid1.Columns.Count - 1
  9. DataGrid1.Col = Colomn1
  10. Debug.Print DataGrid1.Text
  11.  
  12. Next
  13.  
  14. Colomn1 = 0
  15. DataGrid1.Col = Colomn1
  16. For RRow = 0 To 5
  17. DataGrid1.row = RRow
  18. For Colomn1 = 0 To DataGrid1.Columns.Count - 1
  19. DataGrid1.Col = Colomn1
  20. Printer.Print DataGrid1.Text
  21. Next
  22. Next
  23.  
  24. Printer.EndDoc
  25.  
  26. End Sub
  27.  
Dec 27 '11 #1
11 10092
Killer42
8,435 Expert 8TB
Not sure what you mean. What does this code not print, that you want it to?
Dec 27 '11 #2
sorry make you confused, my question is how to print all data from datagrid to my default printer?
Dec 27 '11 #3
Killer42
8,435 Expert 8TB
@hwkong1688
All you've done is repeat the original question. It doesn't give us enough information to work with.

We need more detail to understand exactly what you want from us. You've shown us code which prints data to your default printer. As far as I can tell, you already have exactly what you're asking for. What is it about this code that you're not happy with? What does this code not do, that you want it to? In what way does your existing code not "print all data from datagrid to my default printer"? Please explain.
Dec 28 '11 #4
Sorry my english not so well could be make you don't understand want i mean. you can check back my first post #1 line 16 [For RRow = 0 to 5] this is can only print 6 data from my datagrid to my default printer. How to print all data to my printer. This is my question?
Dec 28 '11 #5
Killer42
8,435 Expert 8TB
Can't you apply the same technique used in line 18, but using Rows.Count instead of Columns.Count?
Dec 28 '11 #6
NeoPa
32,556 Expert Mod 16PB
Thread moved from the Insights forum to the Answers forum. Please be more careful in future where you post your questions to (This is certainly not an Insight).
Dec 28 '11 #7
Sorry noted NeoPa,When i changed Columns.Count to Rows.Count i got this error msg: Compile error:invalid qualifer
Dec 28 '11 #8
Killer42
8,435 Expert 8TB
Damn, how do you determine the number of rows (or should that be "records") in a datagrid? I haven't worked with them in years.

Anyone?
Dec 29 '11 #9
Guido Geurs
767 Expert 512MB
this is how to collect data from a datagrid

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. '§ add reference= Microsoft ActiveX Data Object 2.8 Library
  3. '§ C:\Program Files\Common Files\system\ado\msado15.dll
  4.  
  5. Dim ADO_RECSET As ADODB.Recordset '§ Create a Recordset
  6.  
  7. Private Sub Form_Load()
  8.    Set ADO_RECSET = New ADODB.Recordset
  9.    ADO_RECSET.CursorLocation = adUseClient
  10.    ' Add columns to the Recordset
  11.    ADO_RECSET.Fields.Append "Key", adInteger
  12.    ADO_RECSET.Fields.Append "Field1", adVarChar, 40, adFldIsNullable
  13.    ADO_RECSET.Fields.Append "Field2", adDate
  14.    ' Open the Recordset
  15.    ADO_RECSET.Open , , adOpenStatic, adLockBatchOptimistic
  16.    ' Add data to the Recordset
  17.    ADO_RECSET.AddNew Array("Key", "Field1", "Field2"), _
  18.       Array(1, "string1", Date)
  19.    ADO_RECSET.AddNew Array("Key", "Field1", "Field2"), _
  20.       Array(2, "string2", #1/1/2000#)
  21.    ' Populate the Data in the DataGrid
  22.    Set DataGrid1.DataSource = ADO_RECSET
  23. End Sub
  24.  
  25. Private Sub ComPrint_Click()
  26. Dim FIELDSidx As Integer
  27. Dim ITEMidx As Integer
  28. Dim DATA As String
  29.    ADO_RECSET.MoveFirst
  30.    Do Until ADO_RECSET.EOF = True
  31.       DATA = DATA & vbCrLf
  32.       For ITEMidx = 0 To ADO_RECSET.Fields.Count - 1
  33.          DATA = DATA & ADO_RECSET.Fields.Item(ITEMidx).Value & " - "
  34.       Next
  35.       ADO_RECSET.MoveNext
  36.    Loop
  37.    Text1.Text = DATA
  38. End Sub
  39.  
Instead of putting the data in the textbox, send it to the printer.
Jan 1 '12 #10
Killer42
8,435 Expert 8TB
Seems as though the whole recordset creation thing is rather clouding the issue here.

If I'm not mistaken, the point you're making is that there is no record count, and one must simply loop through all the records. Correct?
Jan 2 '12 #11
Guido Geurs
767 Expert 512MB
Yes, there are different types of grids in VB but for the datagrid like in your call, the way to read the records is to go to the first one, read it, go to the next one, ... until EOF. (see demo attached)
Attached Files
File Type: zip how to print all data from datagrid to printer_v1.zip (2.8 KB, 938 views)
Jan 2 '12 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Spire | last post by:
Does anyone know how to print on POS printer (on com port) from C# (other than using dos command type x.txt>com1)? I have attempted with this but nothing happens IntPtr ptr= CreateFile("COM1",...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. any kind of information is appreciated Thanks...
1
by: Paresh | last post by:
Hi I need to Print asp:datagrid with formatting, which will avoid my writing of crystal reports and can directly print with click of a button. I do not just want to print the current page, I...
2
by: Mitul | last post by:
Hello friends, I am getting stuck at a point in my project. I would like to give functionality of print data from site. but there is a problem is that if there are lots of data which takes...
1
by: ranu s | last post by:
M trying to print image by calling print api (web based application ) As my knowledge is concerned aspnet account wont provide access to netwrk printers ....... My questn is 1)How to print...
1
hariharanmca
by: hariharanmca | last post by:
any know how to Print data through Store Procedure to the printer Directly
3
by: printline | last post by:
Hello Guys I cannot print from a locally installed printer that is mapped to a windows 2003 sever. I have installed the printer locally and can print locally. I connect to the windows 2003...
1
by: vicky87.eie | last post by:
I need to print the image i have drawn in a picture box. My program is create an application similar to paint in windows, I used picture box as the area to draw. Now after completing the work i...
1
by: =?Utf-8?B?SmJhcmJlcg==?= | last post by:
All users in my XP Professional PC were able to print to a network printer until now. Now, the only account that can print to the network printer is the admin account. I have an HP PSC 2200 series...
0
by: Zulqarnain | last post by:
I have developed a report in developer 6i. It properly prints on laser printer but it do not print on receipt printer (CZERLOP). Printing job has sent to printer & printer also detect this job but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.