Sql query from excel vba to access to retrun data that match Array

Viewed 44

I would like to know if there is a way without using loop to get multiply results from database using array?

Lets assume that we got this array:

Dim A As Variant
myUserName  = Array("AAA", "BBB", "CCC")

I want to know if there is a way to pass the array like that:

mySQLst = "SELECT * FROM UserTb WHERE (((UserTb.Nickname)='" & myUserName & "'));"

and get back all users who in the database answer the strings in ther array. I use Access database and Excel vba for this.

thank you for help.

1 Answers

You can use Join:

myUserName  = Array("AAA", "BBB", "CCC")
mySQLst = "SELECT * FROM UserTb WHERE UserTb.Nickname IN ('" & Join(myUserName, "','") & "');"
Related