我正在处理 Access 中的一个对话框,该对话框基本上具有此功能。我希望用户从组合框中选择一个表,然后它会更改查询以创建必要信息的选择视图。这是对话框的代码
Private Sub cmdOK_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Set db = CurrentDb
Set qdf = db.QueryDefs("qryPendingQS")
strSQL = "SELECT [Event Start Date] AS [Event Date], [PO Sent _Date] AS [PO Sent Date], [Brand Name] AS Vendor, PO, [Units _Sold] AS [Units Sold], [Routing Date/Time EST] AS Shipped, [Date and _Time of Arrival] AS ETA, [Department Name] AS Category " & _
"FROM Me.cbotable.Value " & _
"WHERE table3 ='" & Me.cbotable.Value & "';"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryPendingQS"
DoCmd.Close acForm, Me.Name
Set qdf = Nothing
Set db = Nothing
End Sub
大部分情况都很好,但问题出现在声明的这一部分。
strSQL = "SELECT [Event Start Date] AS [Event Date], [PO Sent _Date] AS [PO Sent Date], [Brand Name] AS Vendor, PO, [Units _Sold] AS [Units Sold], [Routing Date/Time EST] AS Shipped, [Date and _Time of Arrival] AS ETA, [Department Name] AS Category " & _
"FROM table3" & _
"WHERE table3 ='" & Me.cbotable.Value & "';"
这是以前的尝试,但我知道您不能根据 WHERE 子句更改表。所以我的问题是,如何根据组合框中选择的内容动态更改 FROM 语句
这是查询尝试执行时 SQL 代码的外观:
SELECT [Event Start Date] AS [Event Date], [PO Sent _Date] AS [PO Sent Date], [Brand Name] AS Vendor, PO, [Units _Sold] AS [Units Sold], [Routing Date/Time EST] AS Shipped, [Date and _Time of Arrival] AS ETA, [Department Name] AS Category
FROM table3
WHERE table3 ='QS Log';