我有一个带有临时表的Access dba,其中存储了所有表名。
表名称:SourceTable
tbl名称字段:SourceID
关键字段:ReferenceID
我想创建一个SELECT查询,其中“ FROM table”实际上是基于SQL查询的动态表名称。与此类似:
Select * from 'select SourceID from SourceTable where ReferenceID=1';
答案 0 :(得分:0)
您也许可以使用VBA做一些事情。
选择表格名称,输入参考ID,然后单击按钮
Private Sub cmdQuery_Click()
Dim qdf As QueryDef 'Query definition containter
Dim mySQL As String 'SQL Statement container
Dim t As String 'table name containter
Dim rid As String 'ReferenceID container
'getting values for your table and ReferenceID
t = cboTableNames.Value
rid = txtRID.Value
'building SQL string
mySQL = "Select * from " & t & " WHERE ReferenceID=" & rid & ";"
'Delete the query if it already exists
DoCmd.DeleteObject acQuery, "NewQuery"
'building query
Set qdf = CurrentDb.CreateQueryDef("NewQuery", mySQL)
'running query
DoCmd.OpenQuery qdf.Name
'closing query
qdf.Close
'clearing memory
Set qdf = Nothing
End Sub