Hi, I have a form and I keep getting Run-time error '3075' Syntax error (comma) in query expression and it keep pointing me to "DoCmd.runsql strAddStudent". I still cannot figure out where is the error. Below is my partial code. Any expert can guide me thru this? I am new to MS Access and coding.
Code:
Private Sub btn_save_Click()
Dim sMissingValues As String
Dim acked As Integer
Dim db As Database
Set db = CurrentDb
Dim strAddStudent As String
sMissingValues = ""
If Len(Me.txtStudentName & vbNullString) = 0 Then sMissingValues = sMissingValues + vbCrLf + "- Student Name is required"
If Len(Me.txtStudentID & vbNullString) = 0 Then sMissingValues = sMissingValues + vbCrLf + "- Student ID is required"
If Len(Me.txtStudentClass & vbNullString) = 0 Then sMissingValues = sMissingValues + vbCrLf + "- Student Class is required"
If sMissingValues <> "" Then
MsgBox prompt:="Please fill in the missing fields:" & vbCrLf & sMissingValues, buttons:=vbCritical, title:="Missing Information"
Else
acked = MsgBox("Confirm to save student record?", vbYesNo)
If acked = vbYes Then
strAddStudent = "insert into tbl_student_details (createdBy, studentName, studentID, studentClass, dateAdded) VALUES ((StrConv([TempVars]![tvarStaffName].[value],1), '" & Me.[txtStudentName] & "', '" & Me.[txtstudentID] & "', '" & Me.[txtstudentClass] & "', NOW() )"
DoCmd.runsql strAddStudent
MsgBox prompt:="Successfully Saved", buttons:=vbInformation, title:="Great"
Else
MsgBox prompt:="Student Record not Save", buttons:=vbInformation, title:="Oh No"
End If
End If
End Sub