I am getting a "Subscript out of Range" Error 9 with my code. I have a Microsoft Access database connected to Excel and a table already made with the Query for Table "QUERY_1". I want to update the table with "QUERY_2" through using VBA. The error occurs on this line:
Set QueryARV = QuerySheet.QueryTables(1)
Here is the full procedure:
Sub ChooseQueryTable()
Dim QueryARV As QueryTable
Dim QuerySheet As Worksheet
Set QuerySheet = ThisWorkbook.Sheets("Sheet1")
Set QueryARV = QuerySheet.QueryTables(1)
With QueryARV
.CommandType = xlCmdTable
.CommandText = "QUERY_1"
.Refresh
End With
End Sub
MsgBox QuerySheet.QueryTables.Countshow you?QuerySheet.QueryTables(1)made me suspectQuerySheet.QueryTables.Countis zero. But I've never actually used QueryTables, so can't suggest how to fix it.