Code:
On Error GoTo cr
If studentave.text = 0 Or (studentave.text < 70 Or studentave.text > 100) Then
MsgBox "invalid 'STUDENT AVERAGE' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf studentfirstname.text = "" Then
MsgBox "invalid 'FIRST NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf studentmiddlename.text = "" Then
MsgBox "invalid 'MIDDLE NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf studentlastname.text = "" Then
MsgBox "invalid 'LAST NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf studentplaceofbirth.text = "" Then
MsgBox "invalid 'PLACE OF BIRTH' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf studenthomeaddress.text = "" Then
MsgBox "invalid 'HOME ADDRESS' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf gender.text = "" Then
MsgBox "invalid 'GENDER' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtfathername.text = "" Then
MsgBox "invalid 'FATHER NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf mothername.text = "" Then
MsgBox "invalid 'MOTHER NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf guardianname.text = "" Then
MsgBox "invalid 'GUARDIAN NAME' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf lastschoolname.text = "" Then
MsgBox "invalid 'SCHOOL LAST ATTENDED NAME ' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf lastschooladdress.text = "" Then
MsgBox "invalid 'SCHOOL LAST ATTENDED ADDRESS' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtcitizenship.text = "" Then
MsgBox "invalid 'citizenship' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtreligon.text = "" Then
MsgBox "invalid 'religion' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtmocc.text = "" Then
MsgBox "invalid 'mother occupation' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtfocc.text = "" Then
MsgBox "invalid 'father occupation' value.this field is required,plese enter a value", vbExclamation, ""
ElseIf txtgocc.text = "" Then
MsgBox "invalid 'guardian occupation' value.this field is required,plese enter a value", vbExclamation, ""
Else
'sql = "insert into studentrecord (firstname,middlename,lastname,placeofbirth,homeaddress,general_average,gender,bithday,father_name,mother_name,guardian_name,mother_phonenumber,father_phonenumber,guardianphonenumber,student_number,schoollastattended,schoollastattendedaddress) values ('" & studentfirstname.text & "','" & studentmiddlename.text & "','" & studentlastname.text & "','" & studentplaceofbirth.text & "','" & studenthomeaddress.text & "','" & studentave.text & "','" & gender.text & "','" & dtbirthdate.Value & "','" & txtfathername.text & "', '" & mothername.text & "','" & guardianname.text & "','" & mothercontact.text & "','" & fathercontact.text & "','" & guardiancontact.text & "','" & studentnumber.Caption & "','" & lastschoolname.text & "','" & lastschooladdress.text & "')"
sql = "select * from studentrecord"
getandsave (sql)
rs.AddNew
rs.Fields("firstname") = Trim(studentfirstname.text)
rs.Fields("middlename") = Trim(studentmiddlename.text)
rs.Fields("lastname") = Trim(studentlastname.text)
rs.Fields("placeofbirth") = studentplaceofbirth.text
rs.Fields("homeaddress") = studenthomeaddress.text
rs.Fields("general_average") = studentave.text
rs.Fields("gender") = gender.text
rs.Fields("bithday") = dtbirthdate.Value
rs.Fields("father_name") = txtfathername.text
rs.Fields("mother_name") = mothername.text
rs.Fields("guardian_name") = guardianname.text
rs.Fields("mother_phonenumber") = mothercontact.text
rs.Fields("father_phonenumber") = fathercontact.text
rs.Fields("guardianphonenumber") = guardiancontact.text
rs.Fields("student_number") = studentnumber.Caption
rs.Fields("schoollastattended") = lastschoolname.text
rs.Fields("schoollastattendedaddress") = lastschooladdress.text
rs.Fields("sy") = GetSetting("parkridge", "enrollment", "activeschoolyear", "")
rs.Fields("religon") = txtreligon.text
rs.Fields("citizenship") = txtcitizenship.text
rs.Fields("mother_occ") = txtmocc.text
rs.Fields("father_occ") = txtfocc.text
rs.Fields("bloodtype") = cboblood.text
rs.Fields("guardian_occ") = txtgocc.text
rs.Fields("fullname") = studentfirstname.text & ", " & studentmiddlename.text & " " & studentlastname.text
'Path
imgfile.Open
imgfile.Type = adTypeBinary
imgfile.LoadFromFile CommonDialog1.FileName
rs.Fields("photo") = imgfile.Read
rs.Update
imgfile.Close
''SSAVE SETTING sa student count
SaveSetting "parkridge", "enrollmentdatabase", "studentcount", student_count
MsgBox "new student information sucessfully added", vbInformation, ""
Call resetfields
'Unload Me
'''herr
End If
Exit Sub
cr:
If Err.number = 13 Then
MsgBox "invalid 'STUDENT AVERAGE' value.this field is required,plese enter a value", vbExclamation, ""
studentave.text = 0
ElseIf Err.number = -2147217900 Then
MsgBox "student already exists in the record!!!", vbExclamation
'Unload Me
Else
MsgBox Err.Description
MsgBox Err.number
End If