Meesha
Meesha

Reputation: 821

SQL Query doesn't recognize the Sheet Name and throws an error

myName = GetmyName() ' gets the name of sheet starting with 'Data' For e.g. sheet name can be 'Data-20150205'
myName = "[" & myName & "$]"
rs.Open " SELECT [State] FROM myName WHERE (([Country]='United States') AND ([Capital]='Boston')) ", cn, adOpenKeyset, adLockReadOnly

Here I get a error that it is unable to find myName, where infact it is one of the sheets. Please correct

Upvotes: 0

Views: 178

Answers (1)

smozgur
smozgur

Reputation: 1812

myName is variable, you need to use it like below:

rs.Open " SELECT [State] FROM " & myName & " WHERE (([Country]='United States') AND ([Capital]='Boston')) ", cn, adOpenKeyset, adLockReadOnly

Upvotes: 3

Related Questions