Anda di halaman 1dari 9

=;Option Explicit

Dim cn As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim oper As String
Dim mchoice As Integer
Dim mrollno As Integer
Dim mNoRec 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

rs.Delete
mNoRec = mNoRec - 1
rs.MoveNext
If mNoRec = 0 Then
MsgBox "No Record Available"
clear
disable
CMDADD.Enabled = True
CMDSAVE.Enabled = False
CMDCANCEL.Enabled = False
Frame1.Enabled = False
Exit Sub
End If
If rs.EOF Then
rs.MoveLast
End If
Display
End If

End Sub

Private Sub CMDEXIT_Click()


Unload Me

End Sub

Private Sub CMDFIRST_Click()


rs.MoveFirst
Display

End Sub

Private Sub CMDLAST_Click()


rs.MoveLast
Display

End Sub

Private Sub Cmdmodify_Click()


disable
txtName.SetFocus

End Sub

Private Sub CMDNEXT_Click()


rs.MoveNext
If rs.EOF Then
MsgBox "Last Record Is Encounted"

rs.MoveLast
End If

Display

End Sub

Private Sub CMDPREVIOUS_Click()


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

End If
Display

End Sub

Private Sub CMDSAVE_Click()


If oper = "ADD" Then
rs.AddNew
mNoRec = mNoRec + 1
oper = ""
End If
rs.Fields("rollno") = txtRollno

rs.Fields("sname") = txtName
If Optmale.Value = True Then

rs.Fields("sex") = "M"

Else
rs.Fields("sex") = "F"

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

Private Sub CMDSEARCH_Click()


mrollno = Val(InputBox("Enter RollNo"))
Do While Not rs.EOF
If rs.Fields("RollNo") = mrollno Then
Display
Exit Sub
End If
rs.MoveNext
Loop
MsgBox "Record does not exist"

End Sub

Private Sub Form_Load()


cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=J:\Demo
PROJECT\test.accdb;Persist Security Info=False "
rs.Open "select count(*)from student ", cn, adOpenDynamic, adLockPessimistic
mNoRec = rs.Fields(0)
rs.Close
rs.Open "select * from student", cn, adOpenDynamic, adLockPessimistic
If mNoRec = 0 Then
MsgBox "No Record Exist"
disable
CMDADD.Enabled = True
CMDSAVE.Enabled = Fal,se
CMDCANCEL.Enabled = False
Frame1.Enabled = False
Exit Sub
Else
Display

End If
able
End Sub
Public Sub Display()
txtRollno = rs.Fields("rollno")
txtName = rs.Fields("sname")

If rs.Fields("sex") = "M" Then

Optmale.Value = True

Else

Optfemale.Value = True

End If
txtdob = rs.Fields("dob")
cmbClass = rs.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()
Frame1.Enabled = False
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()
Frame1.Enabled = True

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

Anda mungkin juga menyukai