473,405 Members | 2,338 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,405 software developers and data experts.

Printing.Datagrid. problem stopping loop

daniel aristidou
491 256MB
Hi i wrote code to print records off a datagrid.the code works on all but one of my data grids. The problem is that loop continues without stopping, Causing the program to crash.
The only diff between all of the grids is the query and the widows form it is on.
I basicly just copied the form changing the SQL for the datasource.
any way so here is the code i typed:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Click()
  2. Dim msg As Variant
  3. Dim spaceaftercolumn1 As Variant
  4. Dim spaceaftercolumn2 As Variant
  5. Dim Spaceaftercolumn4 As Variant
  6. Dim Spaceaftercolumn5 As Variant
  7. Dim Spaceaftercolumn8 As Variant
  8. msg = "Are You Sure You Want to Print All Of The Records?"
  9.  If MsgBox(msg, vbOKCancel, "Print All") = vbOK Then
  10.  
  11.     frmallrecords.grdDataGrid.Row = 0
  12.     Printer.Orientation = 2
  13.     Printer.Font = "Courier New"
  14.     Printer.FontSize = 10
  15.     Printer.FontUnderline = True
  16.     Printer.FontBold = True
  17.     Printer.Print Me.Caption & Space(1) & "-" & Space(1) & Date;
  18.     Printer.Print
  19.     Printer.Print
  20.     Printer.Print "Company" & Space(43) & "First Name" & Space(4) & "Tel" & Space(7) & "Mob" & Space(7) & "Last Seen" & Space(3) & "Today?"
  21.     Printer.Font = "Courier New"
  22.     Printer.FontSize = 10
  23.     Printer.FontUnderline = False
  24.     Printer.FontBold = False
  25.  
  26.         Do While Not frmallrecords.grdDataGrid.Row = datPrimaryRS.Recordset.RecordCount - 1
  27.  
  28.             spaceaftercolumn1 = 50 - Len(frmallrecords.grdDataGrid.Columns(1))
  29.             spaceaftercolumn2 = 14 - Len(frmallrecords.grdDataGrid.Columns(2))
  30.             Spaceaftercolumn4 = 10 - Len(frmallrecords.grdDataGrid.Columns(4))
  31.             Spaceaftercolumn5 = 10 - Len(frmallrecords.grdDataGrid.Columns(5))
  32.             Spaceaftercolumn8 = 12 - Len(frmallrecords.grdDataGrid.Columns(8))
  33.  
  34.             Printer.Print frmallrecords.grdDataGrid.Columns(1) & Space(spaceaftercolumn1) & frmallrecords.grdDataGrid.Columns(2) & Space(spaceaftercolumn2) & frmallrecords.grdDataGrid.Columns(4) & Space(Spaceaftercolumn4) & frmallrecords.grdDataGrid.Columns(5) & Space(Spaceaftercolumn5) & frmallrecords.grdDataGrid.Columns(8) & Space(Spaceaftercolumn8) & "______"
  35.  
  36.             frmallrecords.grdDataGrid.Row = frmallrecords.grdDataGrid.Row + 1
  37.             Loop
  38.  
  39.     spaceaftercolumn1 = 50 - Len(frmallrecords.grdDataGrid.Columns(1))
  40.     spaceaftercolumn2 = 14 - Len(frmallrecords.grdDataGrid.Columns(2))
  41.     Spaceaftercolumn4 = 10 - Len(frmallrecords.grdDataGrid.Columns(4))
  42.     Spaceaftercolumn5 = 10 - Len(frmallrecords.grdDataGrid.Columns(5))
  43.     Spaceaftercolumn8 = 12 - Len(frmallrecords.grdDataGrid.Columns(8))
  44.  
  45.     Printer.Print frmallrecords.grdDataGrid.Columns(1) & Space(spaceaftercolumn1) & frmallrecords.grdDataGrid.Columns(2) & Space(spaceaftercolumn2) & frmallrecords.grdDataGrid.Columns(4) & Space(Spaceaftercolumn4) & frmallrecords.grdDataGrid.Columns(5) & Space(Spaceaftercolumn5) & frmallrecords.grdDataGrid.Columns(8) & Space(Spaceaftercolumn8) & "______"
  46.     Printer.Print
  47.     Printer.EndDoc
  48. End If
I highlited (Bold) the line which seems to be making the problem.I have no solution as to why it is going wrong only on this datagrid when it works fine on all the others.
Can anyone suggest alternative code for that bit?
Another solution i thought of is since the error only occurs when there is no query ie Where statement in the datasource. Does any one know SQL that applies The where function *? i tried this
Expand|Select|Wrap|Line Numbers
  1. select * From Cutomers Where Customers.city = "*" Order by customers.Date_last_seen
However this did not work so i removed the Where Customers.city = "*"
Thank you for any help.!!!
Oct 29 '07 #1
2 1507
daniel aristidou
491 256MB
Anyone got any suggestions? or know a different way to print drawing the info straight from the datasource instead of from the datagrid?
Oct 29 '07 #2
daniel aristidou
491 256MB
Hi all who viewed this.
After allot of trial and error and breakpoints.
I realised the problem only occured when run all at once, if i broke the procedure after every loop the problem did not occur.
Thus i realised that there was a problem with link between datagrid and the ado datasource.
so i tought maybe the time link is available for is not long enough. or that it was not cacheing enough records at once.

I then realized that the datagrid is conrolled directly by the ado.
Thus i could change the "When do not" and go to next record code.
Result 100% Success!!!
Thanks anyone who tried to help me.
The correct code is below if anyone experienced the same errors.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_Click()
  2. Dim msg As Variant
  3. Dim spaceaftercolumn1 As Variant
  4. Dim spaceaftercolumn2 As Variant
  5. Dim Spaceaftercolumn4 As Variant
  6. Dim Spaceaftercolumn5 As Variant
  7. Dim Spaceaftercolumn8 As Variant
  8. msg = "Are You Sure You Want to Print All Of The Records?"
  9.  If MsgBox(msg, vbOKCancel, "Print All") = vbOK Then
  10.  
  11.     datprimaryrs.recordset.movefirst
  12.     Printer.Orientation = 2
  13.     Printer.Font = "Courier New"
  14.     Printer.FontSize = 10
  15.     Printer.FontUnderline = True
  16.     Printer.FontBold = True
  17.     Printer.Print Me.Caption & Space(1) & "-" & Space(1) & Date;
  18.     Printer.Print
  19.     Printer.Print
  20.     Printer.Print "Company" & Space(43) & "First Name" & Space(4) & "Tel" & Space(7) & "Mob" & Space(7) & "Last Seen" & Space(3) & "Today?"
  21.     Printer.Font = "Courier New"
  22.     Printer.FontSize = 10
  23.     Printer.FontUnderline = False
  24.     Printer.FontBold = False
  25.  
  26.         Do While Not datprimaryrs.recordset.eof
  27.             spaceaftercolumn1 = 50 - Len(frmallrecords.grdDataGrid.Columns(1))
  28.             spaceaftercolumn2 = 14 - Len(frmallrecords.grdDataGrid.Columns(2))
  29.             Spaceaftercolumn4 = 10 - Len(frmallrecords.grdDataGrid.Columns(4))
  30.             Spaceaftercolumn5 = 10 - Len(frmallrecords.grdDataGrid.Columns(5))
  31.             Spaceaftercolumn8 = 12 - Len(frmallrecords.grdDataGrid.Columns(8))
  32.  
  33.             Printer.Print frmallrecords.grdDataGrid.Columns(1) & Space(spaceaftercolumn1) & frmallrecords.grdDataGrid.Columns(2) & Space(spaceaftercolumn2) & frmallrecords.grdDataGrid.Columns(4) & Space(Spaceaftercolumn4) & frmallrecords.grdDataGrid.Columns(5) & Space(Spaceaftercolumn5) & frmallrecords.grdDataGrid.Columns(8) & Space(Spaceaftercolumn8) & "______"
  34.  
  35.             datprimaryrs.recordset.movenext
  36.             Loop
  37.  
  38.     Printer.EndDoc
  39. End If
Oct 30 '07 #3

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

Similar topics

2
by: JasmineC | last post by:
Hi there! I'm having some problems printing out my windows form. Here's what I need to do: I need to print a datagrid off a windows form, however the datagrid is bigger than screen. When I tried...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
4
by: Jay | last post by:
Still can't seem to find a solution to printing a lengthy datagrid on multiple pages including datagrid headeron each page. I am not using Crystal Reports or Reporting Services or VStudio. Any...
5
by: ComputerStop | last post by:
I am attempting to print a datagridview. I have not found any method that works successfully. Has any one been successful with this?
4
by: Fred | last post by:
Hello, datagrids have GridLines, BorderWidth, BorderColor, ItemStyle.CssClass, ShowFooter ... properties, which can be used to customize the way they look when printed, how does one achieve the...
6
by: D | last post by:
I have a simple file server utility that I wish to configure as a Windows service - using the examples of the Python Win32 book, I configured a class for the service, along with the main class...
1
by: nvneeraj | last post by:
Please help me how to print data in DOS format and stopping paper after printing in XP through network.
0
by: menyki | last post by:
pls i designed a database application using visual basic. i have done the coding for the print incase i want to print out the data. Pls my problem is how to code at design time for the...
2
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.