underlying query with variable table name

E

Eric

How do I work a variable table name into a form's record
source property?

Such as:
SELECT " & Forms!Orders!txtUser & "Parts.intPartID
FROM " & Forms!Orders!txtUser & "Parts;
 
D

Douglas J. Steele

You'll have to build the SQL dynamically and then change the form's
recordsource property:

strSQL = "SELECT " & Forms!Orders!txtUser & "Parts.intPartID " & _
"FROM " & Forms!Orders!txtUser & "Parts"
Me.Recordsource = strSQL

However, it looks as though you're storing essentially the same information
in multiple tables, and that you're essentially hiding important information
(the user's name) as part of the table's name.

You should have a single table, and store the user's name as an additional
field in that table.

If you do that, then your query would be

SELECT Parts.intPartID
FROM Parts
WHERE UserId = Forms!Orders!txtUser
 
Top