Hi folks
The following code transfers tha data from access database to excelsheet and then printogg the excelsheet. But what I want is when the user click on button then instead of printing off the sheet, It should open up on the screen. so the user can view the data without printing the sheet off. Can anyone please help me?
Thanks
Aman
The following code transfers tha data from access database to excelsheet and then printogg the excelsheet. But what I want is when the user click on button then instead of printing off the sheet, It should open up on the screen. so the user can view the data without printing the sheet off. Can anyone please help me?
Code:
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim r As Long
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Documents and Settings\Amanpreet Kaur\Desktop\ODH System.mdb;"
Set rs = New ADODB.Recordset
strsql = "Select username as Username,date1 as [Date],RecDNo,Surname,Initial,PolicyNo,Team,Address1,Address2,Address3,Address4,Postcode,RetRecDNo,Dochanded,handedto from tblmaster where Date1 = # " & Format(DateSerial(ComboBox3, ComboBox2, ComboBox1), "mm/dd/yyyy") & " # and Team='" & ComboBox4.Value & "'"
rs.Open strsql, cn
Dim wb As Workbook
Dim ws As Worksheet
Set wb = ActiveWorkbook
Set ws = ThisWorkbook.Worksheets("sheet3")
For colIndex = 0 To rs.Fields.Count - 1
ws.Cells(1, colIndex + 1) = rs.Fields(colIndex).Name
Next
ws.Cells(2, 1).CopyFromRecordset rs
Const xlLandscape = 2
Dim J As Integer
Dim i As Integer
J = ActiveSheet.UsedRange.Rows.Count
i = J - 1
ws.Rows(1).Font.Bold = True
ws.UsedRange.Columns.AutoFit
With ws.PageSetup
.CenterHeader = "&""Arial,Bold""&14" & "MI Report"
.LeftHeader = "&""Arial,Bold""&14" & "Total Volume of ODH per team per day = " & i
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
ws.PrintOut
Aman