[CODE title="visual basic 6.0 access database" highlight="1,163"]Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
Dim confirm As Integer
Private Sub addnew_Click()
rs.addnew
clear
txtclient.SetFocus
End Sub
Sub clear()
txtclient.Text = ""
txtfirstname.Text = ""
txtlastname.Text = ""
txtage.Text = ""
DTPicker1.Value = "01/01/0001"
Option1.Value = False
Option2.Value = False
txtadd.Text = ""
txtphone.Text = ""
txtemail.Text = ""
Image1.Picture = LoadPicture("")
End Sub
Private Sub deletebtn_Click()
If MsgBox("Are you sure you want to delete this Record?", vbOKCancel + vbQuestion, "Deleting") = vbOK Then
If rec.State = 1 Then rec.Close
rec.Open "Delete from ClientTBL where ClientNo like'" + txtclient.Text + "'", con, 3, 2
If rec.State = 1 Then rec.Close
rec.Open "Insert into ClientArchiveTBL values('" + txtclient.Text + "','" + txtfirstname.Text + "','" + txtlastname.Text + "','" + txtage.Text + "','" + DTPicker1.Value + "','" + Option1.Value + "','" + Option2.Value + "','" + txtadd.Text + "','" + txtphone.Text + "','" + txtemail.Text + "','" + Image1.Picture + "')", con, 3, 2
MsgBox "Record Successfully Deleted", vbOKOnly + vbInformation, "Delete"
rs.Update
Else
MsgBox "Account Not Deleted.", vbInformation, "Message"
End If
End Sub
Private Sub firstbtn_Click()
rs.MoveFirst
display
End Sub
Private Sub Form_Load()
con.Open "provider = microsoft.jet.OLEDB.4.0;data source=" & App.Path & "/REJAY.mdb"
rs.Open "Select * from ClientTBL", con, adOpenDynamic, adLockPessimistic
display
End Sub
Private Sub lastbtn_Click()
rs.MoveLast
display
End Sub
Private Sub mnuExit_Click()
Dim msg As String
Dim Cancel As Integer
Cancel = 1
msg = MsgBox("Are you sure you want to Close the System?", vbYesNo + vbCritical, "Confirm Exit")
If msg = vbYes Then
frmmain.Hide
Unload frmlogin
End If
End Sub
Private Sub mnuLogout_Click()
frmmain.Hide
Load frmlogin
frmlogin.Show
frmlogin.clear
frmlogin.Refresh
frmlogin.txtuser.SetFocus
End Sub
Private Sub mnuUserManagement_Click()
frmmain.Hide
Load frmuserman
frmuserman.Show
frmuserman.Refresh
End Sub
Private Sub nextbtn_Click()
rs.MoveNext
If Not rs.EOF Then
display
Else
rs.MoveFirst
display
End If
End Sub
Private Sub previousbtn_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveLast
display
Else
display
End If
End Sub
Private Sub savebtn_Click()
rs.Fields("ClientNo").Value = txtclient.Text
rs.Fields("FirstName").Value = txtfirstname.Text
rs.Fields("LastName").Value = txtlastname.Text
rs.Fields("Age").Value = txtage.Text
rs.Fields("DOB").Value = DTPicker1.Value
If Option1.Value = True Then
rs.Fields("Gender") = Option1.Caption
Else
rs.Fields("Gender") = Option2.Caption
End If
rs.Fields("Address").Value = txtadd.Text
rs.Fields("Phone").Value = txtphone.Text
rs.Fields("Email").Value = txtemail.Text
rs.Fields("Photo").Value = str
MsgBox "Data is saved successfully ..!!!", vbInformation
rs.Update
End Sub
Private Sub uploadbtn_Click()
CommonDialog1.ShowOpen
CommonDialog1.Filter = "Jpeg|*.jpg"
str = CommonDialog1.FileName
Image1.Picture = LoadPicture(str)
End Sub
Sub display()
txtclient.Text = rs!ClientNo
txtfirstname.Text = rs!FirstName
txtlastname.Text = rs!LastName
txtage.Text = rs!Age
DTPicker1.Value = rs!DOB
If rs!Gender = "Male" Then
Option1.Value = True
Else
Option2.Value = True
End If
txtadd.Text = rs!Address
txtphone.Text = rs!Phone
txtemail.Text = rs!Email
Image1.Picture = LoadPicture(rs!Photo)
End Sub
[/CODE]