General discussion

Locked

Access - set RecordSource from variable?

By mrmolio ·
I have a drop-down combo box in a form with 10 values (say A, B, C, etc.). I would like to change the RecordSource property of the form based on what is selected from the combo box. Is this possible?

I tried storing the combo value, which match the names of the tables, to a variable (strSource), and then using the following line of code:

Me!RecordSource = "SELECT * FROM strSource"

But SQL tries to interpret the variable name literally. In other words, it can't find a table named "strSource".

I can do it with an IF or Select statement, but I'm just wondering if there is a way to get the SQL statement here to read from a variable.

thanks!

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Access - set RecordSource from variable?

by Peyison In reply to Access - set RecordSource ...

You need to use string concatenation to do this:

Me!RecordSource = "Select * From " & strSource

VBA will resolve the string first, and then assign it to RecordSource.

Hope this helps.

Collapse -

Access - set RecordSource from variable?

by mrmolio In reply to Access - set RecordSource ...

Thanks, that worked.

Collapse -

Access - set RecordSource from variable?

by mrmolio In reply to Access - set RecordSource ...

This question was closed by the author

Back to Web Development Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums