var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: using a variable instead of table name in SQL query
would it be possible to use a variable in the FROM statement of an access query? I thought of something like
where GetTable() is a public function of a module, returning a string, but it does not work.
FROM GetTable() AS A;
Thanks in Advance,
Where are you trying to do this?
If you are in code, it would be something like:
You can then create an object variable for a query, open the query through code, assign your SQL statement as the source SQL, save the query and then run it.
Dim sSQL As String
sSQL = "SELECT A.* FROM " & GetTable() & " AS A;"
If you want to simply use this as the actual source SQL for the query with a variable (function) as the sources, you may be out of luck in Access.
click to email Independent Development Consultant
Biz db & reports - SQL, Access, Crystal, Seradex and more
Small, custom, unique programs - Office, VBA, .NET
Favorite message from Windows:
There was an error displaying the previous error message
Sadly, there was no error number to look up ...
Thanks for your immediate reply,
I tried the following and it worked for my purposes.
I first created an arbitary query named "qry_test" and then execute the code
Is that what you ment?
Public Function mod_test_func()
Dim db As Database
Dim qdf As QueryDef
Dim strSQL As String
Dim name_tab As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qry_test")
name_tab = "tab_test"
strSQL = "SELECT * FROM " & name_tab & ";"
qdf.SQL = strSQL