Hello, I am working in Access and Excel 2003. Here is my goal: to create a copy of an existing Excel template in vba from access, paste results of a vba-defined query recordset into the Excel workbook and open the workbook. My entire code is below. To give a little detail: the macro is supposed to create a query that joins two tables (Task and Pay)- giving details on how much employees made per task. The Excel template has several sheets, where A1 contains the name of the respective tasks. I am getting a 'could not find an installable ISAM' error where I try to open a connection between access and excel.
What I have done so far is verify that the file Msexcl40.dll is registered under the correct path in the Registry Editor, as outlined in the Microsoft help article. I also ran an Office installation repair from Control Panel. That didn't help. I have absolutely no knowledge about setting up connections between Excel and Access, so please let me know if I am missing something very basic.
What I have done so far is verify that the file Msexcl40.dll is registered under the correct path in the Registry Editor, as outlined in the Microsoft help article. I also ran an Office installation repair from Control Panel. That didn't help. I have absolutely no knowledge about setting up connections between Excel and Access, so please let me know if I am missing something very basic.
PHP:
Sub squery()
Dim dbs As Database
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim TaskString As String
Dim strSQL As String, contract As String
Dim intRow As Integer
Dim i As Integer
Set dbs = CurrentDb
Dim countrecords As Long
strSQL = "Select * from Pay inner join Task on Pay.EMPLID= Task.EMPLID "
'Dim xlApplication As Excel.Application
'Dim xlWorkbook As Excel.Workbook
Set xlApplication = CreateObject("Excel.Application")
xlApplication.Visible = False
FileCopy Source:="H:\BUDGET Reporting\TEST\test report template.xls", Destination:="H:\BUDGET Reporting\TEST\ Test Report output"
'this is where I get the error:
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"H:\WTC BUDGET Reporting\WTC TEST\ Test Report output;" & _
"Extended Properties=""Excel 8.0;HDR=Yes"";"
Set rs = New ADODB.Recordset
rs.ActiveConnection = cn
For Each ws In Activeworkbook.worksheets
TaskString = ws.range("A1").Value
strSQL2 = strSQL & "where FTE.Task like '" & TaskString & "';"
Set qrydef = dbs.CreateQueryDef(testquery, strSQL2)
Set rs = qrydef.OpenRecordset
rs.MoveLast
countrecords = rs.RecordCount
rs.MoveFirst
Activesheet.range("A" & countrecords + 2 & ":A2").entirerow.insert
Actoveworkbook.Activesheet.Cells.CopyFromRecordset rs
rs.Close
Next
xlApplication.Visible = True
Activeworkbook.Save
Activeworkbook.Open
cn.Close
End Sub