单击 Access 表单上的按钮将数据添加到特定列的 table

Button click on Access form adds data to a table for specific column

我有一个带有 CWTButton 的 MS Access 表单 单击时,我试图用“是”填充 Table“原始数据”列“CWT”。 我的编程知识真的很有限,所以任何帮助将不胜感激。

Private Sub CWTButton_Click()
INSERT INTO Raw Data (CWT)
VALUES ("Yes");
End Sub

我也试过了

Private Sub CWTButton_Click()
Dim db As Database
Dim rs As DAO.Recordset

Set re = db.Raw Data
rs.AddNew
re("CWT").Value = "Yes"
rs.Update
End Sub

修复代码感谢@Gustav

Private Sub CWTButton_Click()

Dim Sql As String

Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES ('" & Me!Date.Value & "', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', '" & Me!Length.Value & "', '" & Me!Fish_ID.Value & "','" & Me!Comment.Value & "','Yes');"
CurrentDb.Execute Sql

结束子

试试这个:

Private Sub CWTButton_Click()

    Dim Sql As String
    
    Sql = "INSERT INTO [Raw Data] (CWT, Fish, Location) VALUES ('Yes', '" & Me!Fish.Value & "'," & Me!Location.Value & ");"
    CurrentDb.Execute Sql

End Sub

' or:

Private Sub CWTButton_Click()

    Dim rs As DAO.Recordset

    Set rs = CurrentDb.OpenRecordset("[Raw Data]")
    rs.AddNew
        rs.Fields("CWT").Value = "Yes"
    rs.Update
    rs.Close
    
End Sub

对于日期时间([日期])或数字(长度、ID)字段,不使用引号:

Sql = "INSERT INTO [RawData] ([Date], Staff, Species, Location, Length, Fish_ID, Comment, CWT) VALUES (#" & Format(Me!Date.Value, "yyyy\/mm\/dd" & "#', '" & Me!Staff.Value & "', '" & Me!Species.Value & "', '" & Me!Location.Value & "', " & Me!Length.Value & ", " & Me!Fish_ID.Value & ",'" & Me!Comment.Value & "','Yes');"