huynguyenbd > 01-11-11, 10:05 AM
Private Sub cmdthem_Click()
On Error GoTo loi
Dim ma As String, ten As String, ngaysinh As Date, tuoi As Long
Dim bang As Recordset
ma = Me.txtma
ten = Me.txtten
ngaysinh = Me.txtngaysinh
tuoi = Year(Now()) - Year(ngaysinh)
Set bang = CurrentDb.OpenRecordset("select * from sinhvien")
bang.FindFirst ("masv= '" & ma & "'")
If Not bang.NoMatch Then
MsgBox "Masv: " & ma & " da co, nhap lai", vbInformation, "Thong bao"
bang.Close
Exit Sub
Else
If ngaysinh > Now() Then
MsgBox "Ngay sinh phai nho hon ngay hien tai", vbInformation, "Thong bao"
bang.Close
Exit Sub
ElseIf MsgBox("Ban co muon them sinh vien nay khong?", vbQuestion + vbYesNo) = vbYes Then
bang.AddNew
bang!masv = ma
bang!ten = ten
bang!ngaysinh = ngaysinh
bang!tuoi = tuoi
bang.Update
End If
End If
loi:
Select Case Err
Case 94
MsgBox "Vui long nhap day du thong tin can them", vbInformation, "Thong bao"
Exit Sub
Case 13
MsgBox "Ngay sinh phai theo dinh dang dd/mm/yyyy", vbInformation, "Thong bao"
Exit Sub
End Select
End Sub
Noname > 01-11-11, 11:40 AM
huynguyenbd > 01-11-11, 03:55 PM