MainForm.vb

 Public Class MainForm
    Public Enum Database
        Access2003
        Access2007
        theother
    End Enum
    Dim i As Integer = 0
    Public ChooseDb As Database = Database.Access2003

    Private Sub OrderTab()
        For Each tab As TabPage In Me.TabConDB.TabPages
            Me.TabConDB.TabPages.Remove(tab)
        Next
        Me.trvTables.Nodes.Clear()
        With Me.TabConDB.TabPages
            Select Case ChooseDb
                Case Database.Access2003
                    .Add(tbAccess2003)
                Case Database.Access2007
                    .Add(tbAccess2007)
                Case Else
                    'the others
            End Select
        End With
    End Sub

    Private Sub cboDatabase_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboDatabase.SelectedIndexChanged
        Select Case Me.cboDatabase.Text
            Case "Access 2003"
                ChooseDb = Database.Access2003
            Case "Access 2007"
                ChooseDb = Database.Access2007
            Case Else
                'the others
        End Select
        OrderTab()
    End Sub

    Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        OrderTab()
    End Sub

    Private Sub btnFileAccess2003_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileAccess2003.Click
        On Error Resume Next
        Dim DgOpen As New OpenFileDialog
        With DgOpen
            .Title = "Access 2003 (*.mdb)"
            .Filter = "File Access  (*.mdb)|*.mdb"
            .ShowDialog()
            If .CheckFileExists = True Then txtFileAccess2003.Text = .FileName
        End With
    End Sub

    Private Sub btnFileAccess2007_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileAccess2007.Click
        On Error Resume Next
        Dim DgOpen As New OpenFileDialog
        With DgOpen
            .Title = "Access 2007 (*.accdb)"
            .Filter = "File Access  (*.accdb)|*.accdb"
            .ShowDialog()
            If .CheckFileExists = True Then txtFileAccess2007.Text = .FileName
        End With
    End Sub

    Private Sub btnOpenDbase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenDbase.Click
        Select Case ChooseDb
            Case Database.Access2003
                If txtFileAccess2003.Text = "" Then btnFileAccess2003_Click(Nothing, Nothing)
                If txtPassAccess2003.Text = "" Then
                    ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Password='';User ID=Admin;Data Source='" & txtFileAccess2003.Text & "';"
                Else
                    ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Password='" & txtPassAccess2003.Text & "';User ID=Admin;Data Source='" & txtFileAccess2003.Text & "';"
                End If
            Case Database.Access2007
                If txtFileAccess2007.Text = "" Then btnFileAccess2007_Click(Nothing, Nothing)
                If txtPassAccess2007.Text = "" Then
                    ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & txtFileAccess2007.Text & "';Persist Security Info=False;"
                Else
                    ConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & txtFileAccess2007.Text & "';Jet OLEDB:Database Password='" & txtPassAccess2007.Text & "';"
                End If
            Case Else
                'the others
                ConnString = ""
        End Select
        txtConnString.Text = ConnString
        EnumerateTable()

    End Sub

    Private Sub EnumerateTable()
        On Error Resume Next
        If txtConnString.Text = "" Then Exit Sub
        Cursor = Cursors.WaitCursor
        trvTables.Nodes.Clear()
        Select Case ChooseDb
            Case Database.Access2003
                Dim database As New clsDatabase.OleDBase(ConnString)
                Dim trnode As TreeNode
                For Each tmp As String In database.EnumerateTables
                    trnode = Me.trvTables.Nodes.Add(tmp)
                    For Each tmp2 As String In database.EnumerateFields(tmp)
                        trnode.Nodes.Add(tmp2)
                    Next
                Next
                Me.Text = "Database Query 1.00 (Access 2003: " & txtFileAccess2007.Text & ")"
            Case Database.Access2007
                Dim database As New clsDatabase.OleDBase(ConnString)
                Dim trnode As TreeNode
                For Each tmp As String In database.EnumerateTables
                    trnode = Me.trvTables.Nodes.Add(tmp)
                    For Each tmp2 As String In database.EnumerateFields(tmp)
                        trnode.Nodes.Add(tmp2)
                    Next
                Next
                Me.Text = "Database Query 1.00 (Access 2007: " & txtFileAccess2007.Text & ")"
            Case Else
                trvTables.Nodes.Clear()
        End Select
        Cursor = Cursors.Default
    End Sub

    Private Sub btnConnStringCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnStringCheck.Click
        EnumerateTable()
    End Sub

    Private Function cmdSelect() As String
        On Error Resume Next
        Dim tmp2 As String = "Select "
        If Me.trvTables.SelectedNode.Level = 0 Then
            For Each tmp As TreeNode In Me.trvTables.SelectedNode.Nodes
                tmp2 = tmp2 + Splitx(tmp.Text) + ", "
            Next
            If Me.trvTables.SelectedNode.Text.Contains(" ") <> True Then
                tmp2 = Strings.Left(tmp2, Len(tmp2) - 2) + " from " & Me.trvTables.SelectedNode.Text
            Else
                tmp2 = Strings.Left(tmp2, Len(tmp2) - 2) + " from [" & Me.trvTables.SelectedNode.Text & "]"
            End If

        Else
            For Each tmp As TreeNode In Me.trvTables.SelectedNode.Parent.Nodes
                tmp2 = tmp2 + Splitx(tmp.Text) + ", "
            Next
            If Me.trvTables.SelectedNode.Parent.Text.Contains(" ") <> "" Then
                tmp2 = Strings.Left(tmp2, Len(tmp2) - 2) + " from " & Me.trvTables.SelectedNode.Parent.Text
            Else
                tmp2 = Strings.Left(tmp2, Len(tmp2) - 2) + " from [" & Me.trvTables.SelectedNode.Parent.Text & "]"
            End If
        End If
        Return tmp2
    End Function

    Private Function Splitx(ByVal value As String, Optional ByVal isName As Boolean = True) As String
        On Error Resume Next
        If isName = True Then
            Dim tmp As String() = value.Split("(")
            Return tmp(0).ToString.Trim
        Else
            Dim tmp As String() = value.Split("(")
            Return tmp(1).ToString().Replace(")", "").Replace("Long Integer", "Double").Replace("Single", "Double").Replace("Currency", "Double").Replace("Currency", "Double").Replace("Text", "String")
        End If
    End Function

    Private Sub mnuSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSelect.Click
        txtQuery.Text = cmdSelect()
        txtQuery.Select()
    End Sub

    Private Sub mnuSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSearch.Click
        On Error Resume Next
        If Me.trvTables.SelectedNode.Level = 0 Then
            Dim que As String = InputBox("Value to find", "Search Record")
            If que = "" Then Exit Sub
            Dim temp As String
            Me.Cursor = Cursors.WaitCursor
            Dim tmpnode As TreeNode
            tmpnode = Me.trvTables.SelectedNode
            For Each tmp3node As TreeNode In tmpnode.Nodes
                If tmp3node.Text.IndexOf(" (") > 0 Then
                    temp = Strings.Left(tmp3node.Text, tmp3node.Text.IndexOf(" ("))
                Else
                    temp = tmp3node.Text
                End If

                If Test("Select * from " & tmpnode.Text & " where " & temp & " like '%" & que & "%';") = True Then
                    Me.txtQuery.Text = "Select * from " & tmpnode.Text & " where " & temp & " like '%" & que & "%';"
                    Query()
                End If
            Next
            Me.Cursor = Cursors.Default
        End If
    End Sub

    Private Sub btnClearQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearQuery.Click
        txtQuery.Text = ""
    End Sub

    Private Function Test(ByVal cmdQuery As String) As Boolean
        Select ChooseDb
            Case Database.Access2003
                Dim database As New clsDatabase.OleDBase(ConnString)
                Try
                    If database.ToDataSet(cmdQuery).Tables.Count > 0 Then
                        If database.ToDataSet(cmdQuery).Tables.Item(0).Rows.Count > 0 Then
                            Return True
                        Else
                            Return False
                        End If
                    Else
                        Return False
                    End If
                Catch ex As Exception
                    Return False
                End Try
            Case Database.Access2007
                Dim database As New clsDatabase.OleDBase(ConnString)
                Try
                    If database.ToDataSet(cmdQuery).Tables.Count > 0 Then
                        If database.ToDataSet(cmdQuery).Tables.Item(0).Rows.Count > 0 Then
                            Return True
                        Else
                            Return False
                        End If
                    Else
                        Return False
                    End If
                Catch ex As Exception
                    Return False
                End Try
            Case Else
                'the others
        End Select
    End Function

    Public Sub Query()
        If Me.txtQuery.Text = "" Then Exit Sub
        Me.Cursor = Cursors.WaitCursor
        Select Case ChooseDb
            Case Database.Access2003
                Dim database As New clsDatabase.OleDBase(ConnString)
                If Strings.Left(Me.txtQuery.Text.ToLower, 7) = "select " Then
                    i = i + 1
                    If txt1.Text = "" Then
                        database.ToDataGrid(Me.dgv1, Me.txtQuery.Text)
                        Me.TabResult.SelectTab(Me.tbPage1)
                        Me.txt1.Text = Me.txtQuery.Text
                        Me.Status.Text = "Number Records : " & Me.dgv1.RowCount.ToString
                    Else
                        Dim newTab As New TabPage
                        Dim newTextbox As New TextBox
                        Dim newlstResult As New DataGridView
                        Dim newStatus As New StatusBar
                        newTab.Name = "Page" & i.ToString
                        newTab.Text = "Result " & i.ToString
                        newTextbox.Name = "txtAddress" & i.ToString

                        newTextbox.Size = New System.Drawing.Size(593, 20)
                        newTextbox.Location = New System.Drawing.Point(6, 6)
                        newTextbox.Enabled = True

                        newStatus.Name = "status" & i.ToString
                        newStatus.Location = New System.Drawing.Point(3, 308)

                        newlstResult.Name = "lstResult" & i.ToString
                        SetGridview(newlstResult)
                        newTab.Show()

                        TabResult.TabPages.Add(newTab)
                        newTab.Controls.Add(newTextbox)
                        newTab.Controls.Add(newStatus)
                        newTab.Controls.Add(newlstResult)

                        database.ToDataGrid(newlstResult, Me.txtQuery.Text)

                        TabResult.SelectTab(newTab)
                        newTextbox.Text = Me.txtQuery.Text
                        newStatus.Text = "Number Records : " & newlstResult.RowCount.ToString
                    End If
                Else
                    If database.Execute(Me.txtQuery.Text) = True Then
                        MsgBox("Done", MsgBoxStyle.Exclamation)
                        EnumerateTable()
                    Else
                        MsgBox("Error", MsgBoxStyle.Critical)
                    End If
                End If

            Case Database.Access2007
                Dim database As New clsDatabase.OleDBase(ConnString)
                If Strings.Left(Me.txtQuery.Text.ToLower, 7) = "select " Then
                    i = i + 1
                    If txt1.Text = "" Then
                        database.ToDataGrid(Me.dgv1, Me.txtQuery.Text)
                        Me.TabResult.SelectTab(Me.tbPage1)
                        Me.txt1.Text = Me.txtQuery.Text
                        Me.Status.Text = "Number Records : " & Me.dgv1.RowCount.ToString
                    Else
                        Dim newTab As New TabPage
                        Dim newTextbox As New TextBox
                        Dim newlstResult As New DataGridView
                        Dim newStatus As New StatusBar
                        newTab.Name = "Page" & i.ToString
                        newTab.Text = "Result " & i.ToString
                        newTextbox.Name = "txtAddress" & i.ToString

                        newTextbox.Size = New System.Drawing.Size(593, 20)
                        newTextbox.Location = New System.Drawing.Point(6, 6)
                        newTextbox.Enabled = True

                        newStatus.Name = "status" & i.ToString
                        newStatus.Location = New System.Drawing.Point(3, 308)

                        newlstResult.Name = "lstResult" & i.ToString
                        SetGridview(newlstResult)
                        newTab.Show()

                        TabResult.TabPages.Add(newTab)
                        newTab.Controls.Add(newTextbox)
                        newTab.Controls.Add(newStatus)
                        newTab.Controls.Add(newlstResult)

                        database.ToDataGrid(newlstResult, Me.txtQuery.Text)

                        TabResult.SelectTab(newTab)
                        newTextbox.Text = Me.txtQuery.Text
                        newStatus.Text = "Number Records : " & newlstResult.RowCount.ToString
                    End If
                Else
                    If database.Execute(Me.txtQuery.Text) = True Then
                        MsgBox("Done", MsgBoxStyle.Exclamation)
                        EnumerateTable()
                    Else
                        MsgBox("Error", MsgBoxStyle.Critical)
                    End If
                End If

            Case Else
                'the others
        End Select
        Dim tmp As Boolean = True
        For Each Data As String In Me.cboRecent.Items
            If Me.txtQuery.Text = Data Then tmp = False
        Next
        If tmp = True Then
            Dim newQuery As String = Me.txtQuery.Text.Replace(Chr(13), "").Replace(Chr(10), "")
            Me.cboRecent.Items.Add(newQuery)
            Me.cboRecent.Text = newQuery
        End If
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub SetGridview(ByVal GridName As DataGridView)
        With Gridname
            .Size = New System.Drawing.Size(590, 270)
            .Location = New System.Drawing.Point(9, 34)
            .AllowUserToAddRows = False
            .AllowUserToDeleteRows = False
            .RowHeadersVisible = False
            .SelectionMode = DataGridViewSelectionMode.FullRowSelect
        End With
    End Sub

    Private Sub btnExecuteQuery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExecuteQuery.Click
        Query()
    End Sub

    Private Sub trvTables_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles trvTables.AfterSelect
        If Me.trvTables.SelectedNode.Level = 0 Then
            For Each tmpnode As TreeNode In Me.trvTables.Nodes
                tmpnode.ForeColor = Color.Black
            Next
            Me.trvTables.SelectedNode.ForeColor = Color.Red
        End If
    End Sub

    Private Sub mnRClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRClose.Click
        If Me.TabResult.TabPages.Count > 1 Then Me.TabResult.TabPages.Remove(Me.TabResult.SelectedTab)
    End Sub

    Private Sub mnRCloseOther_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRCloseOther.Click
        If Me.TabResult.TabPages.Count > 1 Then
            For Each tb As TabPage In Me.TabResult.TabPages
                If tb.Name <> Me.TabResult.SelectedTab.Name Then Me.TabResult.TabPages.Remove(tb)
            Next
        End If
    End Sub

    Private Sub btnClearRecents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearRecents.Click
        Me.cboRecent.Text = ""
        Me.cboRecent.Items.Clear()
    End Sub
End Class

Project Homepage: