B
B
bender30002016-11-24 14:54:13
Database
bender3000, 2016-11-24 14:54:13

Why does UPDATE NOT ALWAYS work in VBA?

I have a condition to update a record if studentid and subjectid match and add a new record if there is no matching record. Sometimes a new record is created, I could not identify the error.
Private Sub effort1_AfterUpdate()
Dim updateSQL, insertSQL As String
If DLookup("[studentid]", "dbo_marks", "[dbo_marks].[studentid] = " & Me.student_list.Column(0, 0)) And DLookup(" [subjectid]", "dbo_marks", "[dbo_marks].[subjectid] = " & Me.subject) Then
updateSQL = "Update dbo_marks SET effort = '" & Me.effort1 & "' WHERE studentid = " & Me.student_list .Column(0, 0) & " And subjectid = " & Me.subject & "; "
CurrentProject.Connection.
insertSQL = " Insert Into dbo_marks(studentid, subjectid, effort) values ​​(" & Me.student_list.Column(0, 0) & ", " & Me.subject & ", '" & Me.effort1 & "');"
CurrentProject.Connection.Execute(insertSQL)
End If

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question