You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MS Access窗体传递表名至查询时无法识别数据/方法的问题

Access中无法识别控件相关方法/数据问题排查

我使用了一段用于在Access中传递表名作为查询参数的代码,代码如下:

Option Compare Database
Option Explicit

Private Sub Form_Current()
    Dim tblStr As String
    Dim dbObj As DAO.Database, tdObj As DAO.TableDef

    Set dbObj = CurrentDb()
    Me.tableNameCombo.RowSourceType = "SELECT ProductRecipeList.[Product Recipe Name] FROM ProductRecipeList; "
    For Each tdObj In db.TableDefs
        If Left(tdObj.Name, 4) <> "MSys" Then tblStr = tblStr & tdObj.Name & ";"
    Next

    tblStr = Left(tblStr, Len(tblStr) - 1)
    Me.tableNameCombo.RowSource = tblStr
    Set dbObj = Nothing
End Sub

Private Sub runQueryBtn_Click()
    Dim dbObj As DAO.Database, qdObj As DAO.QueryDef
    If Me.tableNameCombo.ListIndex = -1 Then
        MsgBox "Table Name needs to be selected, before continuing.", vbCritical
        Exit Sub
    End If

    Set dbObj = CurrentDb()
    Set qdObj = dbObj.QueryDefs("qry_Tmp")

    qdObj.SQL = "SELECT " & Me.tableNameCombo & ".* FROM " & Me.tableNameCombo & ";"

    qdObj.Execute dbFailOnError

运行这段代码时,无法识别相关方法/数据:
无法识别相关方法/数据

但在表达式字段中却能看到对应的内容:
表达式字段中可见内容

请问我哪里出错了?

已验证以下内容:

  • 控件名称正确:
    控件名称验证
  • 确认Me对象中存在对应数据

内容的提问来源于stack exchange,提问作者Raman Mehat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 06:12:13