Dear
Please need your help on following code its giving me error in INSERT INTO condition the error is "Syntax error in INSERT INTO statement" and some time its give error "Too few Parameters. expected 1."
This code is mentioned on form and on form their is page tabs i am calling this code from page tab name "Personal Details" i dont know is it necessary to change coding for this or ok with above.
thanks & regards,
MA
Please need your help on following code its giving me error in INSERT INTO condition the error is "Syntax error in INSERT INTO statement" and some time its give error "Too few Parameters. expected 1."
Code:
Option Compare Database
Private Sub cmdAdd_Click()
'When we click on button add their are two options
'1. for insert
'2. for update
If Me.txtemployeeno.Tag & "" = "" Then
'this is for insert new
'add data to table
CurrentDb.Execute "INSERT INTO tblPersonalDetails(EmpID, EmployeeName, Surname, DOB, MaritalStatus, Gender, Nationality, Department, Jobtitle, Religion, ImageAddress, Notes)" & _
" VALUES (" & Me.txtemployeeno & ",'" & Me.txtemployeename & "','" & Me.cmbGender & "', '" & Me.cmbMaritalstatus & "','" & Me.cmbNationality & "','" & _
Me.cmbDepartment & "','" & Me.cmbJobtitle & "','" & Me.cmbReligion & "','" & Me.txtSurname & "','" & Me.txtdateofbirth & "', '" & Me.txtPicAddress & "','" & Me.txtMemo & "')"
Else
'otherwise (tag of txtemployeeno store the id of tblpersonaldetails to be modified)
CurrentDb.Execute "UPDATE tblPersonaldetails " & _
"SET EmpID=" & Me.txtemployeeno & _
",EmployeeName='" & Me.txtemployeename & "'" & _
",Surname='" & Me.txtSurname & "'" & _
",DOB = '" & Me.txtdateofbirth & "'" & _
",MaritalStatus = '" & Me.cmbMaritalstatus & "'" & _
",Gender = '" & Me.cmbGender & "'" & _
",Nationality = '" & Me.cmbNationality & "'" & _
",Department = '" & Me.cmbDepartment & "'" & _
",Jobttitle = '" & Me.cmbJobtitle & "'" & _
",Religion = '" & Me.cmbReligion & "'" & _
",ImageAddress = '" & Me.txtPicAddress & "'" & _
",Notes = '" & Me.txtMemo & "'" & _
"WHERE EmpID=" & Me.txtemployeeno.Tag
End If
'Clear form
cmdClear_Click
'refresh data in list on form
formfrmPersonaldetails_subformForm.Form.Requery
End Sub
Private Sub cmdclose_Click()
DoCmd.Close
End Sub
Private Sub cmdClear_Click()
Me.txtemployeeno = ""
Me.txtemployeename = ""
Me.cmbDepartment = ""
Me.txtdateofbirth = ""
Me.cmbGender = ""
Me.cmbJobtitle = ""
Me.cmbMaritalstatus = ""
Me.cmbNationality = ""
Me.cmbReligion = ""
Me.txtPicAddress = ""
Me.txtSurname = ""
Me.txtMemo = ""
'focus on ID text box
Me.txtemployeeno.Set
End Sub
Private Sub cmddelete_Click()
'delete record
'check existing selected record
If no(Me.frmpersonaldetails_subform.Form.Recordset.EOF And Me.frmpersonaldetails_subform.Recordset.BOF) Then
'confirm delete
If MsgBox("Are you Sure you want to delete the record?", vbYesNo) = vbYes Then
'delete now
CurrentDb.Execute "DELETE FROM tblPersonaldetails " & _
"WHERE EmpID =" & Me.frmpersonaldetails_subform.Form.Recordset.Fields("EmpID")
'refresh data in list
Me.Form.frmpersonaldetails_sub.Requery
End If
End If
End Sub
Private Sub cmdEdit_Click()
'Check whether there is exist data in list
If no(Me.frmpersonaldetails_subform.Form.Recordset.EOF And Me.frmpersonaldetails_subform.Recordset.BOF) Then
'get data to text box control
With Me.frmpersonaldetails_subform.Form.Recordset
Me.txtemployeeno = .Fields("EmpID")
Me.txtemployeename = .Fields("EmployeeName")
Me.cmbDepartment = .Fields("Department")
Me.txtdateofbirth = .Fields("DOB")
Me.cmbGender = .Fields("Gender")
Me.cmbNationality = .Fields("Nationality")
Me.cmbJobtitle = .Fields("Jobtitle")
Me.cmbReligion = .Fields("Religion")
Me.txtSurname = .Fields("Surname")
Me.txtMemo = .Fields("Notes")
Me.txtPicAddress = .Fields("ImageAddress")
Me.cmbMaritalstatus = .Fields("MaritalStatus")
'store id of tblPersonalDetails in tag of txtEmpID in case id is modified
Me.txtemployeeno.Tag = .Fields("EmpID")
'change caption of button add to update
Me.cmdAdd.Caption = "Update"
'disable button edit
Me.cmdEdit.Enabled = False
End With
End If
End Sub
This code is mentioned on form and on form their is page tabs i am calling this code from page tab name "Personal Details" i dont know is it necessary to change coding for this or ok with above.
thanks & regards,
MA