Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Twitter Updates

    News

    New site design will be posted by Wednesday.
    6/2/2008 8:07:00 AM

    Windows Mobile Developer Controls
    Sapphire Soltuions
    Skip Navigation Links Breadcrumb Articles Breadcrumb Past Blast BreadcrumbStarting Out

    eVB Database Viewer

    Written by Jason Freih  [author's bio]  [read 64043 times]
    Edited by Derek

    Download the code

    Page 1  Page 2  Page 3  Page 4  Page 5  Page 6 

    Private Sub cmdGetDatabase_Click()
    'Open Dialog Box and Select File
    Dim sDataBase As String
    'Open the Common Dialog and retreive the Database
    CommonDialog1.Filter = "Database|*.mdb;*.cdb"
    CommonDialog1.ShowOpen
    sDataBase = CommonDialog1.FileName
    'Read In the Tables Located In Main Module
    LoadDB sDataBase

    Me.lblDispMsg.Caption = "Select Table or SQL Retreival"
    cmdGetTable.Visible = True

    BtnShow ("011000000")

    'Hide Instructions
    'The words as well as the lines
    Me.lblDesc1.Visible = False
    Me.lblDesc2.Visible = False
    Me.Line1.Visible = False
    Me.Line2.Visible = False
    Me.Line3.Visible = False
    Me.Line4.Visible = False
    Me.Line5.Visible = False
    End Sub

    CODE 3 (Form)

    The LoadDB() is located in the Main Module, it opens the selected database, and names it conndb

    Private Sub LoadDB(dbFileName As String)
    'Open the Database
    Dim rsRecs As ADOCE.Recordset
    'Open conndb, while it acts as a database, we are in fact
    'opening a connection to get our information
    Set conndb = CreateObject("ADOCE.Connection.3.0")
    conndb.ConnectionString = "data source = " & dbFileName
    conndb.Open
    End Sub

    CODE 4 (Main Module)

    Please Note, that the function BtnShow(), is used to control which button is hidden, which is visible. It's concept is very simple 1=On and 0=Off

    Private Sub BtnShow(sDispBtns As String)
    'Each position in the sDispBtns variable, is assigned to a button
    'Start buy hiding all the buttons
    cmdGetDataBase.Visible = False
    cmdGetTable.Visible = False
    cmdSQL.Visible = False
    cmdViewGrid.Visible = False
    cmdViewRecs.Visible = False
    cmdPrev.Visible = False
    cmdNext.Visible = False
    cmdFirst.Visible = False
    cmdLast.Visible = False

    'If the corresponding position for a button is set to one then make the button visible

    If Mid(sDispBtns, 1, 1) = "1" Then cmdGetDataBase.Visible = True
    If Mid(sDispBtns, 2, 1) = "1" Then & _
    cmdGetTable.Visible = True
    If Mid(sDispBtns, 3, 1) = "1" Then & _
    cmdSQL.Visible = True
    If Mid(sDispBtns, 4, 1) = "1" Then & _
    cmdViewGrid.Visible = True
    If Mid(sDispBtns, 5, 1) = "1" Then & _
    cmdViewRecs.Visible = True
    If Mid(sDispBtns, 6, 1) = "1" Then & _
    cmdPrev.Visible = True
    If Mid(sDispBtns, 7, 1) = "1" Then & _
    cmdNext.Visible = True
    If Mid(sDispBtns, 8, 1) = "1" Then & _
    cmdFirst.Visible = True
    If Mid(sDispBtns, 9, 1) = "1" Then & _
    cmdLast.Visible = True
    End Sub

    CODE 5 (Form)

    Once the user selects the database to view, the Select Database button is replaced by two other buttons. Select Table and Run SQL Command

    The View Table button, let's the user select a table from a Combo box, the other lets' the user write a select statement. For the most part the Select statement is for the more sophisticated user. Providing the ability to combine more then one table into a view, and select only those fields and records required.

    I will start by taking you down the Table View path.

    The first step is to Load a List of Available Tables in to the Combo Box.

    Private Sub cmdGetTable_Click()
    'Display ComboBox with the List of Tables
    txtBox = " "
    LoadList
    List1.Visible = True
    List1.SetFocus
    BtnShow ("000110000")
    Me.lblDispMsg.Caption = "Select Table from Combo Box Above"
    End Sub

    CODE 6 (Form)

    The LoadList Function populates the Combo Box, in our example called List1

    Private Sub LoadList()
    'Load all the Table Names in to the ComboBox
    Dim RecordCount As Integer
    Dim xCounter1 As Integer

    'Load List of Tables in the rsTables Recordset
    Set rsTables = CreateObject("ADOCE.Recordset.3.0")
    rsTables.Open "MSysTables", conndb
    RecordCount = rsTables.RecordCount
    ' If you do not clear the list then, the list of
    ' tables in the combo box will grow, displaying the tables
    ' from a previously selected database
    List1.Clear
    'Starting the Counter at 0 will display the Msys tables
    'which hold the internal information about your
    'database. If you do not wish the users to see
    'this information start the counter form 4
    For xCounter1 = 0 To RecordCount - 1
    List1.AddItem rsTables.Fields("TableName").Value
    rsTables.MoveNext
    Next
    rsTables.Close
    Set rsTables = Nothing
    End Sub

    CODE 7 (Form)

    Previous Page  Next Page