Hi guys
Please see the code below. It works fine but in the report that gets printed off, it doesn't display grid lines and line numbers . Can it be done?
Please can anyone help me in this?
Private Sub CommandButton1_Click()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=J:\System1.mdb;"
Set rs = New ADODB.Recordset
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Dim J As Integer
Dim i As Integer
Dim a As Date
Dim t As Date
strsql = "select BatchNo,PolicyNo,CustInitial as [customer Initial],custSurname as [Customer Surname],BarcodeRef,DocumentType,DocumentProvenance,Status from tblmain where InputDate>= #" & Format(DateSerial(ComboBox3, ComboBox2, ComboBox1), "mm/dd/yyyy") & "# and Inputdate <= #" & Format(DateSerial(ComboBox6, ComboBox5, ComboBox4), "mm/dd/yyyy") & "# and Status='Retain and send to PWR'"
rs.Open strsql, cn
Set ws = ThisWorkbook.Worksheets("sheet1")
For colIndex = 0 To rs.Fields.Count - 1
ws.Cells(1, colIndex + 1) = rs.Fields(colIndex).Name
Next
ws.Cells(2, 1).CopyFromRecordset rs
ws.Rows(1).Font.Bold = True
ws.UsedRange.Columns.AutoFit
With ws.PageSetup
' .LeftHeader = "&""Arial""&10" & "Date: " & Format(DateSerial(ComboBox3, ComboBox2, ComboBox1), "dd/mm/yyyy")
.CenterHeader = "&""Arial,Bold""&14" & b & " MI Report from " & a & " to " & t
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
' .FitToPagesTall = 1
End With
Answer = MsgBox("Do you want to print this report?", vbQuestion + vbYesNo + vbDefaultButton2)
If Answer = vbYes Then
ws.PrintOut
MsgBox "The report has been printed"
End If
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub
Bookmarks