You are on page 1of 8

vOption Explicit

Dim oper As String


Dim mchoice As Integer
Dim mrollno As Integer

Private Sub CMDADD_Click()


oper = "ADD"
clear
disable
txtRollno.SetFocus
End Sub

Private Sub CMDCANCEL_Click()


oper = ""
Display
able

End Sub

Private Sub CMDDELETE_Click()


mchoice = MsgBox("Are you Sure", vbYesNo + vbQuestion)
If mchoice = vbYes Then
stu.Recordset.Delete
stu.Recordset.MoveNext
If stu.Recordset.RecordCount = 0 Then
MsgBox "No Record Available"

Exit Sub
End If
If stu.Recordset.EOF Then
stu.Recordset.MoveLast
End If
Display
End If

End Sub

Private Sub CMDEXIT_Click()


Unload Me

End Sub

Private Sub CMDFIRST_Click()


stu.Recordset.MoveFirst
Display

End Sub

Private Sub CMDLAST_Click()


stu.Recordset.MoveLast

Display

End Sub

Private Sub CMDNEXT_Click()


stu.Recordset.MoveNext
If stu.Recordset.EOF Then
MsgBox "Last Record Is Encounted"
stu.Recordset.MoveLast
End If

Display

End Sub

Private Sub CMDPREVIOUS_Click()


stu.Recordset.MovePrevious
If stu.Recordset.BOF Then
MsgBox "First Record Is Encounted"
stu.Recordset.MoveFirst

End If
Display

End Sub

Private Sub CMDSAVE_Click()


If oper = "ADD" Then
stu.Recordset.AddNew
oper = ""
End If
stu.Recordset.Fields("rollno") = txtRollno
stu.Recordset.Fields("sname") = txtName
If Optmale.Value = True Then

stu.Recordset.Fields("sex") = "M"

Else
stu.Recordset.Fields("sex") = "F"

End If
stu.Recordset.Fields("dob") = txtdob
stu.Recordset.Fields("class") = cmbClass
stu.Recordset.Update
able
End Sub

Private Sub CMDSEARCH_Click()


mrollno = Val(InputBox("Enter RollNo"))
stu.Refresh

Do While Not stu.Recordset.EOF


If stu.Recordset.Fields("RollNo") = mrollno Then
Display
Exit Sub
End If
stu.Recordset.MoveNext
Loop
MsgBox "record does not exist"

End Sub

Private Sub Form_Load()


stu.Refresh
If stu.Recordset.RecordCount <> 0 Then
Display
Else
MsgBox "Table Is Empty"
End If
able
End Sub
Public Sub Display()
txtRollno = stu.Recordset.Fields("rollno")
txtName = stu.Recordset.Fields("sname")

If stu.Recordset.Fields("sex") = "M" Then

Optmale.Value = True

Else

Optfemale.Value = True

End If
txtdob = stu.Recordset.Fields("dob")
cmbClass = stu.Recordset.Fields("class")

End Sub

Public Sub clear()


txtRollno.Text = ""
txtName.Text = ""
txtdob.Text = ""

End Sub

Private Sub txtName_keypress(KeyAscii As Integer)


If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = KeyAscii - 32
End If
End Sub

Private Sub txtRollno_KeyPress(KeyAscii As Integer)


If ((KeyAscii >= 65 And KeyAscii <= 90) Or (KeyAscii >= 97 And KeyAscii < 122))
Then
KeyAscii = 0
End If

End Sub
Public Sub able()
CMDADD.Enabled = True
CMDSAVE.Enabled = False
CMDCANCEL.Enabled = False
CMDDELETE.Enabled = True
CMDFIRST.Enabled = True
CMDPREVIOUS.Enabled = True
CMDNEXT.Enabled = True
CMDLAST.Enabled = True
CMDSEARCH.Enabled = True

End Sub
Public Sub disable()

CMDADD.Enabled = False

CMDSAVE.Enabled = True
CMDCANCEL.Enabled = True
CMDDELETE.Enabled = False
CMDFIRST.Enabled = False
CMDPREVIOUS.Enabled = False
CMDNEXT.Enabled = False
CMDLAST.Enabled = False
CMDSEARCH.Enabled = False

End Sub

You might also like