2017-09-08 48 views
0

我得到以下代碼工作,除了最後一行。訪問VBA代碼:如何定義多個WHERE語句?更新 - 設置 - WHERE語句

所以我想更新一個名爲loggingX的表,這是使用下面的代碼,除了我希望WHERE子句不僅檢查1字段(這是工作),但我希望在WHERE也檢查對於字段WH是一個固定值。

我想知道如何在這裏添加多個部分到我的WHERE語句。只有滿足以下兩個條件才能更新UPDATE。我只有麻煩,並想知道如何將這兩個條件放在WHERE子句中。

任何幫助表示讚賞。

stdid=" & Me.txtID.Tag 
WHid=" & Me.txtWHid 

當前DB完成更新語句(並且不工作):

CurrentDb.Execute "UPDATE loggingX " & _ 
    " SET stdid=" & Me.txtID & _ 
    ", stdname='" & Me.txtName & "'" & _ 
    ", gender='" & Me.cboGender & "'" & _ 
    ", phone='" & Me.txtPhone & "'" & _ 
    ", address='" & Me.txtAddress & "'" & _ 
    ", WHid='" & Me.txtWHid & "'" & _ 
    " WHERE stdid=" & Me.txtID.Tag 
    " AND WHid=" & Me.txtWHid 

親切的問候,彼得 -JAN

回答

0

你錯過了一個符號,並在第二強調最後一行:

CurrentDb.Execute "UPDATE loggingX " & _ 
    " SET stdid=" & Me.txtID & _ 
    ", stdname='" & Me.txtName & "'" & _ 
    ", gender='" & Me.cboGender & "'" & _ 
    ", phone='" & Me.txtPhone & "'" & _ 
    ", address='" & Me.txtAddress & "'" & _ 
    ", WHid='" & Me.txtWHid & "'" & _ 
    " WHERE stdid=" & Me.txtID.Tag & _ 
    " AND WHid=" & Me.txtWHid