为什么当我使用Excel用户窗体更新MS Access中的表时,需要更新的数据不可见?

kmbjn2e3  于 2022-11-26  发布在  其他
关注(0)|答案(1)|浏览(147)

我正在创建一个用户窗体以更新学生出勤详细信息。通过Excel用户窗体更新MS Access中的表时,数据未更新。而是在attendanceStatus列中显示0或-1,在Excuse列this is a picture of my ClassDate table after attempting to update for student IT01 and IT02中不显示任何内容。
我的用户窗体包含courseCode、subject、classDate、studentID、name、attendance status和excuse的值。因此,我将使用classDate、courseCode和studentID的值来查找要更新的学生的出勤情况。这是我尝试使用“用户窗体更新”按钮来更新MS Access ClassDate表中的attendanceStatus和Excuse列。

Private Sub CommandButton1_Click()

Dim cnt As ADODB.Connection
Dim db_path As String
Dim db_str As String

db_path = "C:\Users\Lenovo\Documents\BIT\SEM4\SAD\StudentAttendanceMonitoring\attendance1.accdb;"
Set cnt = New ADODB.Connection

db_str = "provider=Microsoft.ACE.OLEDB.12.0; data source=" & db_path
cnt.Open (db_str)

insert_str = "update Classdate set attendanceStatus = '" & cmbUpdateStatus.Value & "' and Excuse = '" & txtUpdateExcuse.Value & "' where classDate = '" & cmbUpdateDate.Value & "' and courseCode = '" & cmbUpdateCourseCode.Value & "' and studentID = '" & cmbUpdateStudentID.Value & "'"

Debug.Print insert_str

cnt.Execute (insert_str)

MsgBox "Updated sucessfully", vbInformation

Set cnt = Nothing

End Sub
7lrncoxx

7lrncoxx1#

应该用逗号分隔字段更新表达式,而不是and

insert_str = "update Classdate set attendanceStatus = '" & cmbUpdateStatus.Value & _
                               "', Excuse = '" & txtUpdateExcuse.Value & _
             "' where classDate = '" & cmbUpdateDate.Value & _
                    "' and courseCode = '" & cmbUpdateCourseCode.Value & _
                    "' and studentID = '" & cmbUpdateStudentID.Value & "'"

相关问题