I'm trying to create a link from an Access Query to a specific Excel-Sheet.
However when I run the code, I get an Run-time error 424 Object required, debugging shows that fileToOpen does show the correct database but when I mouse over acQuery it says acQuery = Empty.
I've checked the query name a couple of times and it should all be correct.
Public Function ImportAccess()
Dim fileToOpen As Variant
Dim fileFilterPattern As String
fileFilterPattern = "Access Files (*.mdb*),*mdb*"
fileToOpen = Application.GetOpenFilename(fileFilterPattern)
If fileToOpen = False Then
' Input cancelled
MsgBox "No file selected."
Else
DoCmd.TransferDatabase acLink, "Microsoft Access", fileToOpen, acQuery, "Query", "ExcelSheet", True
End If
End Function
In Excel we run calculations on pipediameters and flows based on the information that is created in the Access query. Basically I want the Access Data shown on the "ExcelSheet" sheet, so I can run calculations in Excel on other sheets in the workbook (so the data from Access won't be edited in Excel). The reason that I want to link it is so that I don't have to import data each time a change is made to the AccessDatabase.