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:
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
However this did not work so i removed the Where Customers.city = "*"
Thank you for any help.!!!
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:
Code:
Private Sub Print_Click() Dim msg As Variant Dim spaceaftercolumn1 As Variant Dim spaceaftercolumn2 As Variant Dim Spaceaftercolumn4 As Variant Dim Spaceaftercolumn5 As Variant Dim Spaceaftercolumn8 As Variant msg = "Are You Sure You Want to Print All Of The Records?" If MsgBox(msg, vbOKCancel, "Print All") = vbOK Then frmallrecords.grdDataGrid.Row = 0 Printer.Orientation = 2 Printer.Font = "Courier New" Printer.FontSize = 10 Printer.FontUnderline = True Printer.FontBold = True Printer.Print Me.Caption & Space(1) & "-" & Space(1) & Date; Printer.Print Printer.Print Printer.Print "Company" & Space(43) & "First Name" & Space(4) & "Tel" & Space(7) & "Mob" & Space(7) & "Last Seen" & Space(3) & "Today?" Printer.Font = "Courier New" Printer.FontSize = 10 Printer.FontUnderline = False Printer.FontBold = False Do While Not frmallrecords.grdDataGrid.Row = [B]datPrimaryRS.Recordset.RecordCount - 1[/B] spaceaftercolumn1 = 50 - Len(frmallrecords.grdDataGrid.Columns(1)) spaceaftercolumn2 = 14 - Len(frmallrecords.grdDataGrid.Columns(2)) Spaceaftercolumn4 = 10 - Len(frmallrecords.grdDataGrid.Columns(4)) Spaceaftercolumn5 = 10 - Len(frmallrecords.grdDataGrid.Columns(5)) Spaceaftercolumn8 = 12 - Len(frmallrecords.grdDataGrid.Columns(8)) 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) & "______" frmallrecords.grdDataGrid.Row = frmallrecords.grdDataGrid.Row + 1 Loop spaceaftercolumn1 = 50 - Len(frmallrecords.grdDataGrid.Columns(1)) spaceaftercolumn2 = 14 - Len(frmallrecords.grdDataGrid.Columns(2)) Spaceaftercolumn4 = 10 - Len(frmallrecords.grdDataGrid.Columns(4)) Spaceaftercolumn5 = 10 - Len(frmallrecords.grdDataGrid.Columns(5)) Spaceaftercolumn8 = 12 - Len(frmallrecords.grdDataGrid.Columns(8)) 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) & "______" Printer.Print Printer.EndDoc End If
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
Code:
select * From Cutomers Where Customers.city = "*" Order by customers.Date_last_seen
Thank you for any help.!!!
Comment