I'm fairly new to Access/VBA but I know Excel like a brother. I have a database in Access featuring a VB-module calculation process that perform operations on queries and tables.
I want to write a RecordSet to an Excel file so that each time the calculation process is executed, a new Excel file is generated with an absolute File Name. Should the absolute File Name exist, the written RecordSet will completely overwrite the old File.
How should I do this?
I've tried something like -
Dim xlWrkBk As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim myRec As DAO.Recordset
Dim fldCustName As DAO.Field
Dim xlApp As New Excel.Application
Set xlWrkBk = GetObject("C:\Test.xls")
Set xlSht = xlWrkBk.Worksheets(1)
Set myRec = CurrentDb.OpenRecordset("tblPlantAddress")
Set fldCustName = myRec.Fields("Name")
myRec.MoveFirst
xlSht.Cells(1, "A") = fldCustName
xlWrkBk.Save
- and Access (or VB, not sure which one) does not recognize the custom type Excel.Application or any of those Excel.***'s.
Thanks in advance.
I want to write a RecordSet to an Excel file so that each time the calculation process is executed, a new Excel file is generated with an absolute File Name. Should the absolute File Name exist, the written RecordSet will completely overwrite the old File.
How should I do this?
I've tried something like -
Dim xlWrkBk As Excel.Workbook
Dim xlSht As Excel.Worksheet
Dim myRec As DAO.Recordset
Dim fldCustName As DAO.Field
Dim xlApp As New Excel.Application
Set xlWrkBk = GetObject("C:\Test.xls")
Set xlSht = xlWrkBk.Worksheets(1)
Set myRec = CurrentDb.OpenRecordset("tblPlantAddress")
Set fldCustName = myRec.Fields("Name")
myRec.MoveFirst
xlSht.Cells(1, "A") = fldCustName
xlWrkBk.Save
- and Access (or VB, not sure which one) does not recognize the custom type Excel.Application or any of those Excel.***'s.
Thanks in advance.