Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question