ms access:输入参数值

时间:2015-06-19 22:52:32

标签: ms-access access-vba

我正在尝试点击按钮打开表单。以下是我的代码

Private Sub Command17_Click()
    Dim stuff As String
    Dim salaryStatus As String
    stuff = "Senior Stuff"
    salaryStatus = "Deposit"
    sSQL = "SELECT CustomerT.* FROM CustomerT WHERE (((CustomerT.[Salary Status])=" & salaryStatus & ") AND ((CustomerT.[Stuff Type])= " & stuff & "));"

    DoCmd.OpenForm "clusterF"
    Forms!ClusterF.Form.RecordSource = sSQL
    Forms!ClusterF.Form.Requery
    Forms!ClusterF.Form.Refresh
End Sub

当我点击按钮时,我会看到一个小弹出窗口Enter parameter value stuff and salaryStatus。为什么这个窗口显示。我的SQL查询有什么问题以及如何修复它?

1 个答案:

答案 0 :(得分:-1)

是的,稍微减少它并重命名按钮:

Private Sub Command17_Click()

    Dim stuff        As String
    Dim salaryStatus As String

    stuff = "Senior Stuff"
    salaryStatus = "Deposit"
    sSQL = "SELECT CustomerT.* FROM CustomerT WHERE CustomerT.[Salary Status] = '" & salaryStatus & "' AND CustomerT.[Stuff Type] = '" & stuff & "';"

    DoCmd.OpenForm "clusterF"
    Forms!ClusterF.RecordSource = sSQL
End Sub