Hi all.
I have this ADO code to import data from an Access query to Excel:
This code works perfectly so no problem there, but this new scenario requires the criteria for the query to be a list of varying length within Excel itself, e.g.
So, is it possible to modify my code above to include some script that passes this criteria to the Access query, even if the criteria list will be a different length every time? I want the criteria field in Access to ultimately read:
In("Criteria1", "Criteria2", "Criteria3") etc etc.
Can it be done???!!!
Many thanks people.
R
I have this ADO code to import data from an Access query to Excel:
Code:
Sub Test()
Dim db1 As Database
Dim rs1 As Recordset
Dim intColIndex1 As Integer
Dim mydb1 As String
Dim FieldName1 As String
Dim MyCriteria1 As String
Dim TableName1 As String
TableName1 = "tbl_UK_All_Data"
mydb1 = "P:\Database.mdb"
Set TargetRange = Range("A1")
Set db1 = OpenDatabase(mydb1)
Set rs = db1.OpenRecordset("SELECT * FROM " & TableName)
For intColIndex1 = 0 To rs.Fields.Count - 1
TargetRange.Offset(0, intColIndex).Value = rs.Fields(intColIndex1).Name
Next
TargetRange.Offset(1, 0).CopyFromRecordset rs
Set rs = Nothing
db1.Close
Set db1 = Nothing
End Sub
This code works perfectly so no problem there, but this new scenario requires the criteria for the query to be a list of varying length within Excel itself, e.g.
Column1
Criteria1
Criteria2
Criteria3
Etc...
Etc...
So, is it possible to modify my code above to include some script that passes this criteria to the Access query, even if the criteria list will be a different length every time? I want the criteria field in Access to ultimately read:
In("Criteria1", "Criteria2", "Criteria3") etc etc.
Can it be done???!!!
Many thanks people.
R