Visual Basic Codes Collection

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

VISUAL BASIC CODES COLLECTION

Dim con As New ADODB.Connection DELETE CODE


Dim rs As New ADODB.Recordset Private Sub cmdDelete_Click(Index As
Integer)
Add New
confirm = MsgBox("Are yu sure you want
Private Sub cmdAdd_Click(Index As
to delete this record?", vbYesNo +
Integer)
vbExclamation, "Warning")
rs.AddNew
If confirm = vbYes Then
clear
adocon.Recordset.Delete
txtcandidate.SetFocus
MsgBox "Record deleted successfully!",
End Sub vbInformation, "Delete confirmation"
Else

Clear Code MsgBox "Record not deleted",


vbInformation, "Message confirmation"
Private Sub cmdClear_Click(Index As
Integer) End If

txtcandidate.Text = "" End Sub

txtfname.Text = ""
txtsurname.Text = "" SAVE CODE

combogender.Text = "-Select gender-" Private Sub cmdSave_Click(Index As


Integer)
txtdob.Text = ""
'con.Open
comboclass.Text = "-Select class-"
rs.Fields("CandidateNum").Value =
txtamount.Text = "" txtcandidate.Text
txtcandidate.SetFocus rs.Fields("Fname").Value = txtfname.Text
End Sub rs.Fields("Surname").Value =
txtsurname.Text
rs.Fields("Gender").Value =
combogender.Text
rs.Fields("DOB").Value = txtdob.Text
rs.Fields("Amount").Value = txtamount.Text
rs.Fields("Class").Value = comboclass.Text
MsgBox "Record successfully saved!!", rs.Fields("Surname").Value =
vbInformation txtsurname.Text
rs.Update rs.Fields("Gender").Value =
combogender.Text
End Sub
rs.Fields("DOB").Value = txtdob.Text
rs.Fields("Amount").Value = txtamount.Text
rs.Fields("Class").Value = comboclass.Text
MsgBox "Record successfully updated!!",
vbInformation
SEARCH CODE
rs.Update
Private Sub cmdSearch_Click()
End Sub
rs.Close
rs.Open "Select * from candidates where
surname='" + txtsearch.Text + "'"
FORM LOAD
If Not rs.EOF Then
Private Sub Form_Load()
display
con.Open
reload
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Else Source=C:\Users\Mashava\Documents\
Zimsec.mdb;Persist Security Info=False"
'display
rs.Open "Select*from candidates", con,
MsgBox "Record not found!!", adOpenDynamic, adLockPessimistic
vbInformation
combogender.AddItem "Male"
combogender.AddItem "Female"
End If
comboclass.AddItem "4 EAST"
End Sub
comboclass.AddItem "4 WEST"
comboclass.AddItem "4 NORTH"
UPDATE CODE
comboclass.AddItem "4 SOUTH"
Private Sub cmdUpdate_Click(Index As
Integer) 'display

rs.Fields("CandidateNum").Value = clear
txtcandidate.Text
End Sub
rs.Fields("Fname").Value = txtfname.Text
Sub display() FIRST RECORD CODE
txtcandidate.Text = rs!CandidateNum Private Sub cmdFirst_Click(Index As
Integer)
txtfname.Text = rs!Fname
rs.MoveFirst
txtsurname.Text = rs!Surname
display
combogender.Text = rs!Gender
End Sub
txtdob.Text = rs!DOB
comboclass.Text = rs!Class
LAST RECORD CODE
txtamount.Text = rs!Amount
Private Sub cmdLast_Click(Index As
End Sub
Integer)
rs.MoveLast
display
Sub clear()
End Sub
txtcandidate.Text = ""
txtfname.Text = ""
txtsurname.Text = ""
NEXT RECORD CODE
combogender.Text = "-Select gender-"
Private Sub cmdNext_Click()
txtdob.Text = ""
rs.MoveNext
comboclass.Text = "-Select class-"
If Not rs.EOF Then
txtamount.Text = ""
display
End Sub
Else
MsgBox "There are no more records to
Sub reload() navigate", vbInformation

rs.Close rs.MoveFirst

rs.Open "Select * from candidates", con, display


adOpenDynamic, adLockPessimistic
End If
End Sub
End Sub
PREVIOUS CODE txtdesignation.Text = ""
Private Sub cmdPrevious_Click(Index As txtstartdate.Text = ""
Integer)
txtaddress.Text = ""
rs.MovePrevious
txtphone.Text = ""
If rs.BOF Then
Picture1.Picture = LoadPicture("")
rs.MoveLast
display
End Sub
Else
display
Private Sub cmdClear_Click()
End If
txtec.Text = ""
End Sub
txtsurname.Text = ""
txtnames.Text = ""
Dim conn As New ADODB.Connection
txtdob.Text = ""
Dim rs As New ADODB.Recordset
Option1.Value = False
Dim str As String
Option2.Value = False
Combo1.Text = "Select Deprtment"
Private Sub cmdAddNew_Click()
txtqualification.Text = ""
rs.AddNew
txtdesignation.Text = ""
Clear
txtstartdate.Text = ""
End Sub
txtaddress.Text = ""
Sub Clear()
txtphone.Text = ""
txtec.Text = ""
Picture1.Picture = LoadPicture("")
txtsurname.Text = ""
End Sub
txtnames.Text = ""
txtdob.Text = ""
Private Sub cmdClose_Click()
Option1.Value = False
Unload Me
Option2.Value = False
frmMain.Show
Combo1.Text = "Select Deprtment"
End Sub
txtqualification.Text = ""
Private Sub cmdDelete_Click() Private Sub cmdFirst_Click()
confirm = MsgBox("Are you sure yo want rs.MoveFirst
to delet this record", vbYesNo + vbCritical,
display
"Deletion Confirmation")
End Sub
If confirm = vbYes Then
rs.Delete adAffectCurrent
Private Sub cmdLast_Click()
MsgBox ("Record successfully deleted"),
vbInformation, "Message" rs.MoveLast
rs.Update display
refreshdata End Sub
Else
MsgBox "Record not deleted", Private Sub cmdNext_Click()
vbInformation, "Message"
rs.MoveNext
End If
If Not rs.EOF Then
display
End Sub
Else
rs.MoveFirst
Sub refreshdata()
display
rs.Close
End If
rs.Open "Select * from ProfileTB", conn,
adOpenStatic, adLockPessimistic End Sub

If Not rs.EOF Then


rs.MoveNext Private Sub cmdPrevious_Click()

display rs.MovePrevious

Else If rs.BOF Then

MsgBox "No Record found" rs.MoveLast

End If display

End Sub Else


display
End If
Private Sub cmdSerach_Click()
End Sub rs.Close
'conn.Open
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Private Sub cmdSave_Click()
Source=C:\Users\Mashava\Documents\
rs.Fields("ECNum").Value = txtec.Text ProfileDB.mdb;Persist Security Info=False"

rs.Fields("Surname").Value = rs.Open "Select * from ProfileTB where


txtsurname.Text Surname='" + txtsurname.Text + "'"

rs.Fields("Names").Value = txtnames.Text If Not rs.EOF Then

rs.Fields("DOB").Value = txtdob.Text display

If Option1.Value = True Then reload

rs.Fields("Gender") = Option1.Caption Else

Else display

rs.Fields("Gender") = Option2.Caption MsgBox "Record not found!!",


vbInformation
End If
'rs.Open
rs.Fields("Department").Value =
Combo1.Text End If

rs.Fields("Qualification").Value = conn.Close
txtqualification.Text
'search
rs.Fields("Designation").Value =
'refreshdata
txtdesignation.Text
End Sub
rs.Fields("StartDate").Value =
txtstartdate.Text
rs.Fields("Address").Value = txtaddress.Text
rs.Fields("PhoneNum").Value =
txtphone.Text
Sub search()
rs.Fields("Photo").Value = str
AdoCON.RecordSource = "Select * from
MsgBox "Record saved successfully!!", ProfileTB where ECNum='" + txtec.Text +
vbInformation "' or Surname='" + txtSearch.Text + "'"
rs.Update AdoCON.Refresh
End Sub If AdoCON.Recordset.EOF Then
MsgBox "Record not found, please enter rs.Fields("PhoneNum").Value =
anothe EC Number or Surname to search", txtphone.Text
vbCritical, "Message"
rs.Fields("Photo").Value = str
End If
MsgBox "Record updated successfully!!",
End Sub vbInformation
Sub reload() rs.Update
rs.Close End Sub
rs.Open "Select * from ProfileTB", conn,
adOpenDynamic, adLockPessimistic
Private Sub cmdUpload_Click()
End Sub
CommonDialog1.ShowOpen
CommonDialog1.Filter = "Jpeg|*.jpg"
Private Sub cmdUpdate_Click()
str = CommonDialog1.FileName
rs.Fields("ECNum").Value = txtec.Text
Picture1.Picture = LoadPicture(str)
rs.Fields("Surname").Value =
End Sub
txtsurname.Text
rs.Fields("Names").Value = txtnames.Text
Private Sub Form_Load()
rs.Fields("DOB").Value = txtdob.Text
'Me.Hide
If Option1.Value = True Then
'Login.Show
rs.Fields("Gender") = Option1.Caption
conn.Open
Else
"Provider=Microsoft.Jet.OLEDB.4.0;Data
rs.Fields("Gender") = Option2.Caption Source=C:\Users\Mashava\Documents\
ProfileDB.mdb;Persist Security Info=False"
End If
'AdoCON.
rs.Fields("Department").Value =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Combo1.Text
Source=C:\Users\Mashava\Documents\
rs.Fields("Qualification").Value = ProfileDB.mdb;Persist Security Info=False"
txtqualification.Text
rs.Open "Select * from ProfileTB", conn,
rs.Fields("Designation").Value = adOpenDynamic, adLockPessimistic
txtdesignation.Text
rs.Fields("StartDate").Value =
Combo1.AddItem "SCIENCE"
txtstartdate.Text
Combo1.AddItem "MATHEMATICS"
rs.Fields("Address").Value = txtaddress.Text
Combo1.AddItem "COMMERCIALS" Private Sub cmdSearch_Click()
Combo1.AddItem "HUMANITIES" AdoCON.RecordSource = "Select * from
ProfileTB where ECNum='" +
Combo1.AddItem "PRACTICALS"
txtSearch.Text + "' or Surname='" +
Combo1.AddItem "ENGLISH" txtSearch.Text + "'"

'display AdoCON.Refresh

Clear If AdoCON.Recordset.EOF Then

End Sub MsgBox "Record not found, please enter


anothe EC Number or Surname to search",
vbCritical, "Message"
Sub display() Else
txtec.Text = rs!ECNum AdoCON.Caption =
txtsurname.Text = rs!Surname AdoCON.RecordSource

txtnames.Text = rs!Names End If

txtdob.Text = rs!DOB End Sub

If rs!Gender = "Male" Then


Option1.Value = True
Else
Option2.Value = True
End If
Combo1.Text = rs!Department
txtqualification.Text = rs!Qualification
txtdesignation.Text = rs!Designation
txtstartdate.Text = rs!StartDate
txtaddress.Text = rs!Address
txtphone.Text = rs!PhoneNum
Picture1.Picture = LoadPicture(rs!Photo)
End Sub

You might also like