Results 1 to 6 of 6

Thread: Open a MDB table and show all records in my vb project?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665

    Question Open a MDB table and show all records in my vb project?

    I have a access 2000 mdb. How can I in my vb project show a table from the mdb with all values and all fieldnames?
    How do I do that?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,174

  3. #3
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424
    DataGrid

  4. #4
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    This is how to show all tables, for fields/values isn't difficult,

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3. Dim rs   As ADODB.Recordset
    4. Dim conn As ADODB.Connection
    5.  
    6.     Set conn = New ADODB.Connection
    7.     ListView1.View = lvwReport
    8.     i = 1
    9.     conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Persist Security Info=False"
    10.     Set rs = conn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
    11.     Do While Not rs.EOF
    12.         ListView1.ColumnHeaders.Add , , rs!TABLE_NAME
    13.         rs.MoveNext
    14.     Loop
    15.     rs.Close
    16.     Set rs = Nothing
    17.     conn.Close
    18.     Set conn = Nothing
    19.  
    20. End Sub

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2002
    Posts
    665
    Thanks!

    But if I want to use a ListView. How can I show a complete table in the listview from a mdb? Columnname should be fieldname and all recordsets should be show.
    Last edited by Pirre001; Sep 9th, 2004 at 05:33 AM.

  6. #6
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    Here's part II

    Add's all tables to a listbox then after clicking selected table in listbox will add all respective fields to the coloumn headers in a listview.

    Do you know you can use a flexgrid?

    VB Code:
    1. Set MSHFlexGrid1.DataSource = rs.DataSource

    VB Code:
    1. Option Explicit
    2.  
    3. Private conn       As ADODB.Connection
    4. Private rs         As ADODB.Recordset
    5.  
    6.  
    7. Private Sub Form_Load()
    8.  
    9.     Set conn = New ADODB.Connection
    10.     conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    11.                        "Data Source=" & _
    12.                        "D:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB" & _
    13.                        ";" & _
    14.                        "Persist Security Info=False"
    15.     conn.Open
    16.    
    17.     ListView1.View = lvwReport
    18.     Set rs = conn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "Table"))
    19.     With rs
    20.         Do While Not .EOF
    21.             list1.AddItem !TABLE_NAME
    22.             .MoveNext
    23.         Loop
    24.     End With
    25.  
    26. End Sub
    27.  
    28. Private Sub list1_Click()
    29. Dim i As Integer
    30.     ListView1.ColumnHeaders.Clear
    31.     Set rs = conn.OpenSchema(adSchemaColumns, Array(Empty, Empty, list1.Text))
    32.     With rs
    33.         Do While Not .EOF
    34.             ListView1.ColumnHeaders.Add , , !COLUMN_NAME
    35.             .MoveNext
    36.         Loop
    37.     End With
    38.  
    39. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width