Sunday, September 1, 2019

CRUD ADODB Connection in Visual Basic 6 and Microsoft Access

I this article I would like to share with you sample program written by my close friend, business partner and fellow software engineer Sir Larry Dave Emol a simple CRUD ADODB Connection in Visual Basic 6 and Microsoft Access.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com





Sample Program Output


Program Listing


FORM CODES

Private Sub Command1_Click()
Form1.Show 1
End Sub

Private Sub Command2_Click()
If Me.Tag = "" Then
 MsgBox "Please select data to update", vbCritical, "Crud"
Else
Form1.Text2.Text = Me.Listview1.selectedItem.ListSubItems(3)
Form1.Text3.Text = Listview1.selectedItem.ListSubItems(4)
Form1.Text4.Text = Listview1.selectedItem.ListSubItems(5)
Form1.Command1.Caption = "UPDATE"
Form1.Caption = "UPDATE"
Form1.Show 1, Mainform
End If
End Sub

Private Sub Command3_Click()
'On Error Resume Next
If Me.Tag = "" Then
 MsgBox "Please select data to delete", vbCritical, "Crud"
Else
Set rstUserAcct = New ADODB.Recordset
    If rstUserAcct.State = 1 Then rstUserAcct.Close
    rstUserAcct.Open "Select * from tblInfo where ID like'" & Me.Tag & "'", MyConn, adOpenDynamic, adLockBatchOptimistic
    rstUserAcct.Delete
    rstUserAcct.UpdateBatch
    data
    MsgBox "Successfully Deleted", vbInformation, "DELETE"
    Me.Tag = ""
End If
End Sub

Private Sub Form_Activate()
data
End Sub

Sub data()
On Error Resume Next
Dim lst
Dim cnt As Integer
Dim X As Integer
Set rstUserAcct = New ADODB.Recordset
    If rstUserAcct.State = 1 Then rstUserAcct.Close
    rstUserAcct.Open "Select * from tblInfo", MyConn, adOpenDynamic, adLockBatchOptimistic
    
With Me.Listview1
    .ColumnHeaders.Clear
    .ListItems.Clear
    .ColumnHeaders.Add , , "", 0
    .ColumnHeaders.Add , , "USERNAME", 3000
    .ColumnHeaders.Add , , "PASSWORD", 4000
    .ColumnHeaders.Add , , "FISTNAME", 4000
    .ColumnHeaders.Add , , "MIDDLENAME", 4000
    .ColumnHeaders.Add , , "LASTNAME", 4000
End With
Do Until rstUserAcct.EOF
    Set lst = Listview1.ListItems.Add(, , rstUserAcct.Fields!ID)
            
            lst.ListSubItems.Add , , rstUserAcct.Fields!UserName
            lst.ListSubItems.Add , , rstUserAcct.Fields!Password
            lst.ListSubItems.Add , , rstUserAcct.Fields!firstname
            lst.ListSubItems.Add , , rstUserAcct.Fields!middlename
            lst.ListSubItems.Add , , rstUserAcct.Fields!lastname
  cnt = cnt + 1
rstUserAcct.MoveNext
Loop
Label1.Caption = "Total No. of record(s): " & cnt
End Sub


Private Sub Form_Unload(Cancel As Integer)
End
End Sub


Private Sub Listview1_Click()
Me.Tag = Me.Listview1.selectedItem.Text
End Sub

MODULE CODES

Option Explicit

Public MyConn As ADODB.Connection
Public rstUserAcct As ADODB.Recordset



Sub Main()
On Error Resume Next
        Set MyConn = New ADODB.Connection
        Set rstUserAcct = New ADODB.Recordset
        MyConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & AppDir & "Tutorial.mdb;Persist Security Info=False;Jet OLEDB:Database Password =IT098"
        MyConn.CursorLocation = adUseClient
        'Start up object
        Mainform.Show
End Sub

Public Function AppDir() As String
    If Right$(App.Path, 1) = "\" Then
        AppDir = App.Path
    Else
        AppDir = App.Path & "\"
    End If
End Function



No comments:

Post a Comment