我正在創建一個用戶表單來更新學生出勤詳細資訊。通過 Excel 用戶表單更新 MS Access 中的表時,資料不會更新。相反,它在 attendanceStatus 列上顯示 0 或 -1,而在 Excuse 列中沒有任何內容這是我的 ClassDate 表在嘗試為學生 IT01 和 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
uj5u.com熱心網友回復:
應該是分隔欄位更新運算式的逗號,而不是and.
insert_str = "update Classdate set attendanceStatus = '" & cmbUpdateStatus.Value & _
"', Excuse = '" & txtUpdateExcuse.Value & _
"' where classDate = '" & cmbUpdateDate.Value & _
"' and courseCode = '" & cmbUpdateCourseCode.Value & _
"' and studentID = '" & cmbUpdateStudentID.Value & "'"
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/537432.html
上一篇:顯示銷售額最高的員工
