I'm trying to pull Access Queries based on certain input values. Pulling the correct query works, but it gets stuck on the marked position, because it wont accept a variable and just writes it out as it is.
Is there a workaround anybody knows of?
Dim BDMA As String
BDMA = Me.ListBDMA.Value
ActiveWorkbook.Queries.Add Name:=BDMA, Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Quelle = Access.Database(File.Contents(""X:\Pierburg\Berlin\_Common\010 Standort Berlin\300 Datenbanken\Schichtbericht.accdb""), [CreateNavigationProperties=true])," _
& Chr(13) & "" & Chr(10) & " #""_Band 3"" = Quelle{[Schema="""",Item=" & BDMA & "]}[Data]" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""_Band 3"""
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location="" & BDMA & "";Extended Properties=""""" _
, Destination:=Range("$A$5")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [" & BDMA & "]") '<----- Here is the Problem ----------
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = False
.ListObject.DisplayName = "Band_3"
.Refresh BackgroundQuery:=False
End With
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
Greetings
Error says:
The query '& BDMA &' wasn't found.
That indicates i can't use variables like that. Any ideas? I also tried creating an array or string beforehand and using that, but that also didn't work.


"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location="" & BDMA & "";Extended Properties="""""as there should only be one quotation mark:Location=" & BDMA & ";& "";Extended Properties="""""part can be dropped entirely, So,"OLEDB;Provider=Microsoft...;Data Source=$Wo...;Location=" & BDMA.