trying to change rowsource using VBA

rob_andy

New Member
Joined
Mar 12, 2003
Messages
33
I'm using VBA to try and dynamically change a rowsource query:

SELECT Teams.TeamName, Teams.Sport FROM Teams WHERE (((Teams.Sport)="NBA"));

In VBA as follows:

Select Case Sport.Value

Case "NBA"

Team1.RowSource = "SELECT Teams.TeamName, Teams.Sport FROM Teams WHERE (((Teams.Sport)="NBA")); "

As you can see the "" marks mess everything up. I need NBA to be in "" for the query to work in access but VBA won't have it. Is there a way around this? Please Help, much appreciated. R
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Use three quotation marks consecutively to place a quoation mark in a string.

i.e. this

Debug.Print "some text " & """in quotes""" & " some other text"

will print a string that looks like this

some text "in quotes" some other text
 
Upvote 0

Forum statistics

Threads
1,221,499
Messages
6,160,169
Members
451,629
Latest member
MNexcelguy19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top