如果没有syntax error
错误,此代码将无法执行。我做错了什么?
Private Sub cboInvFindVendorName_AfterUpdate()
Me.cboInvFindDate.RowSource = "SELECT [InvoiceDate] FROM tblInvoices " & _
WHERE [vendorID] = " & Nz(me.cboInvFindVendorname) ORDER by [InvoiceDate]"
End Sub
答案 0 :(得分:1)
我认为之前的答案在nz()
函数周围有错误的引用。另外,通过名称显示该字段是组合框,并且可能更适合引用其精确列,我使用列0,因为这通常是键的绑定列。我不认为提到这个列是一个要求,但我认为只是确定。
Me.cboInvFindDate.RowSource = "SELECT [InvoiceDate] FROM tblInvoices " & _
"WHERE [vendorID] = " & Nz(Me.cboInvFindVendorname.column(0), 0) & " ORDER BY [InvoiceDate]"
答案 1 :(得分:0)
尝试没有'&'在“FROM tblInvoices”之后,如下:
Private Sub cboInvFindVendorName_AfterUpdate()
Me.cboInvFindDate.RowSource = "SELECT [InvoiceDate] FROM tblInvoices
WHERE [vendorID] = " & Nz(me.cboInvFindVendorname) ORDER by [InvoiceDate]"
End Sub
以下是我发现的VBA Access SQL语法示例:
SELECT tblStaff.[Firstname], tblStaff.[Lastname] FROM tblStaff WHERE tblStaff.[Office]="Paris”;
最终代码
Private Sub cboInvFindVendorName_AfterUpdate()
Me.cboInvFindDate.RowSource = "SELECT tblInvoices.[InvoiceDate] FROM tblInvoices
WHERE tblInvoices.[vendorID] = " & Nz(me.cboInvFindVendorname) ORDER by [InvoiceDate]"
End Sub
希望这有帮助,
苏海尔
答案 2 :(得分:0)
你错过了报价和零:
Me.cboInvFindDate.RowSource = "SELECT [InvoiceDate] FROM tblInvoices " & _
"WHERE [vendorID] = " & Nz(Me.cboInvFindVendorname, 0) & " ORDER BY [InvoiceDate]"