2016-11-07 198 views
-5

我是MS Access 2007的新手&我幾乎對vba一無所知。 ...我有一個表名F與字段F1,F2,F3,F4,F5其中前三個是數字字段&後兩個是文本字段。在一個帶有文本框:txtF1,txtF2,txtF3,txtF4,txtF5和命令按鈕cmdUpdate的表單中,我想更新表F中的F5,其中F1 = txtF1,F2 = txtF2,F3 = txtF3和F4 = txtF4條件staisfy。 ..請幫助完整的代碼。ms access access vba code通過表格更新記錄

+1

請閱讀遊覽和[問]。 – Andre

+1

_只是幫助完成code_?你是否用一張白紙走進課堂,並要求你的老師給你答案?嘗試解決問題,如果您的代碼存在特定問題,請返回此處。 – Takarii

回答

0

在cmdUpdate按鈕的單擊事件中,您需要放置一個將生成sql命令的過程,然後執行它。

Private Sub cmdUpdate_Click() 

'Create a string variable to hold your sql command string 
Dim strSQL As String 

'Fill the variable with your sql command, plucking values out of your 
'form as shown using the Me. operator. When using text values in your 
'string, wrap them with the Chr(34)'s, which will insert quotation marks in 
'your sql string when it's resolved. 
strSQL = "UPDATE F SET F.F5 = " & Chr(34) & yourtextvaluehere & Chr(34) & _ 
      " WHERE F1=" & Me.txtF1 & _ 
      " AND F2=" & Me.txtF2 & _ 
      " AND F3=" & Me.txtF3 & _ 
      " AND F4=" & Chr(34) & Me.txtF4 & Chr(34) 

'Execute the sql statement you've built against the database 
CurrentDb.Execute strSQL, dbSeeChanges + dbFailOnError 

End Sub