First off i will let you know the reason i am trying to do this. We are trying to keep our test reports better organized and have created a database that stores the data for each test. Fields include Model; Type; Date Tested; Tested By; Test Procedure; Name of Test; Test Results and the like. Each record is stored with that info and i need to be able to transfer it to our ISO9000 approved form that we keep in excel so we can print it off and get it signed by managers and put into record retention.
So with that being said I am trying to solve a problem with transferring the information from a single record on a form into an excel template that is already formatted the way that i need. So far i have been able to get the info from off the form that is being displayed, and using a query i have written the information in one line on a new table. I intend to be able to push a command button on the form and transfer the data into the formatted excel sheet so far i have this.
Code:
This getting the data from the record that i want and transferring it succesfully to excel but it just puts it in one line starting with the Range that i have specified. I need to split up each cell coming from access and direct them into there coresponding cell in excel. Any Help would be appreciated.
So with that being said I am trying to solve a problem with transferring the information from a single record on a form into an excel template that is already formatted the way that i need. So far i have been able to get the info from off the form that is being displayed, and using a query i have written the information in one line on a new table. I intend to be able to push a command button on the form and transfer the data into the formatted excel sheet so far i have this.
Code:
Code:
Private Sub Command40_Click()DoCmd.SetWarnings False
DoCmd.OpenQuery "qry_Export"
DoCmd.SetWarnings True
Dim oExcel As New Excel.Application
Dim WB As New Excel.Workbook
Dim WS As Excel.Worksheet
Dim rng As Excel.Range
Dim objConn As New ADODB.Connection
Dim objRs As New ADODB.Recordset
Const sFileNameTemplate As String = "D:\DATA\ACCESS\ExcelTemplates\TestReportTemp.xls"
Dim sSQL As String
Set objConn = CurrentProject.Connection
sSQL = "Select * from tbl_Export" 'This has to be the name of the query/table your report is using to display data
With oExcel
.Visible = True
'Create new workbook from the template file
Set WB = .Workbooks.Add(sFileNameTemplate)
With WB
Set WS = WB.Worksheets("Sheet1") 'Replace with the name of actual sheet
With WS
objRs.Open sSQL, objConn, adOpenStatic, adLockReadOnly
Set rng = .Range("A2") 'Starting point of the data range
rng.CopyFromRecordset objRs
objRs.Close
End With
End With
.Quit
End With
Set objConn = Nothing
Set objRs = Nothing
End Sub
This getting the data from the record that i want and transferring it succesfully to excel but it just puts it in one line starting with the Range that i have specified. I need to split up each cell coming from access and direct them into there coresponding cell in excel. Any Help would be appreciated.