Any help would be great. I am stuck with this issue for last two days. Thanks
I am trying to update a excel sheet from access using access macro. The code works fine for second object but not for first.
I am getting the error on objxl.Workbooks.Open FileName:=Trim(strfname)
Note: I am linking this tables to create table in access.
Here is my code
Public objxl, objxl1, objxl2 As excel.Application
Private Sub Command2_Click()
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim dbs As Database
Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("CUST", dbOpenDynaset)
Set rst2 = dbs.OpenRecordset("customer", dbOpenDynaset)
DoCmd.Hourglass True
Dim strPath As String
Dim xlApp As Object
Dim xlSheet As Object
Dim strfname As String
Set objxl = CreateObject("Excel.application")
Set objxl2 = CreateObject("Excel.application")
strfname = "C:\Contract_IDS\AHC_CUSTOMER.xls"
'objxl.Workbooks.Open strfname
objxl.Workbooks.Open FileName:=Trim(strfname)
objxl.Application.Run "AHC_CUST"
objxl.Workbooks.Close
objxl.Quit
strfname = "C:\Contract_IDS\AHC_CUSTOMER_HAS.xls"
objxl2.Workbooks.Open FileName:=strfname
objxl2.Application.Run "AHC_Customer_Has"
objxl2.Workbooks.Close
objxl2.Quit
Set objxl = Nothing
Set objxl2 = Nothing
end sub
In excel I have the following code:
Selection.QueryTable.Refresh BackgroundQuery:=False ActiveWorkbook.Save
any help would be great. Thanks
I am trying to update a excel sheet from access using access macro. The code works fine for second object but not for first.
I am getting the error on objxl.Workbooks.Open FileName:=Trim(strfname)
Note: I am linking this tables to create table in access.
Here is my code
Public objxl, objxl1, objxl2 As excel.Application
Private Sub Command2_Click()
Dim rst1 As Recordset
Dim rst2 As Recordset
Dim dbs As Database
Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("CUST", dbOpenDynaset)
Set rst2 = dbs.OpenRecordset("customer", dbOpenDynaset)
DoCmd.Hourglass True
Dim strPath As String
Dim xlApp As Object
Dim xlSheet As Object
Dim strfname As String
Set objxl = CreateObject("Excel.application")
Set objxl2 = CreateObject("Excel.application")
strfname = "C:\Contract_IDS\AHC_CUSTOMER.xls"
'objxl.Workbooks.Open strfname
objxl.Workbooks.Open FileName:=Trim(strfname)
objxl.Application.Run "AHC_CUST"
objxl.Workbooks.Close
objxl.Quit
strfname = "C:\Contract_IDS\AHC_CUSTOMER_HAS.xls"
objxl2.Workbooks.Open FileName:=strfname
objxl2.Application.Run "AHC_Customer_Has"
objxl2.Workbooks.Close
objxl2.Quit
Set objxl = Nothing
Set objxl2 = Nothing
end sub
In excel I have the following code:
Selection.QueryTable.Refresh BackgroundQuery:=False ActiveWorkbook.Save
any help would be great. Thanks
Last edited: