Using a Treeview to List Tables & Fields 
Author Message
 Using a Treeview to List Tables & Fields

I successfully created a form that, after choosing a database, will fill a
combobox with the TableNames...
I also created another combobox so that, when you clicked on a table name,
will list the field names.

Then, I tried to do the same thing with a Treeview, except, list them all at
once, when the database (Access) is chosen. However, I can't even get past
the tablename part -- the project freezes & crashes my computer....Here's
the code I'm using:
        strDB = cdledit.FileTitle
        txtDatabase.Text = strDB
        Data1.DatabaseName = cdledit.FileName
        Set db = OpenDatabase(txtDatabase.Text)
        Tv1.Nodes.Add , , "RootNode", strDB

        cboTables.Clear
        For Each td In db.TableDefs
            strTablename = td.Name

            If Mid(strTablename, 1, 4) <> "MSys" Then
                cboTables.AddItem strTablename
'Up to the above statement, it works fine - the following line is where it
freezes:
                Tv1.Nodes.Add "RootNode", tv1Child, strtablename,
strTablename
            End If

         Next
If anyone can help or give me a hint of why it's happening, please let me
know.
David Wier



Wed, 27 Feb 2002 03:00:00 GMT  
 Using a Treeview to List Tables & Fields
OK - I've got it working sort of....The only way I could get it working is
if I had the Treeview on a separate form. I click on a button to choose the
NorthWind database.
Here's my code:

    For Each td In db.TableDefs
    strTablename = td.Name
    Set MyRs = db.OpenRecordset(strTablename)
        If Mid(strTablename, 1, 4) <> "MSys" Then

            Form1.tvwTest.Nodes.Add "RootNode", tvwChild, strTablename,
strTablename

' -- My problem comes here - if I leave the next For/Next Loop out of the
code, I get all the table names listed...If I leave it in, I only get three
of the tables. All the Field names for each Table shows up, as far as I can
tell.

            For i = 0 To MyRs.Fields.Count - 1
                Form1.tvwTest.Nodes.Add strTablename, tvwChild,
MyRs.Fields(i).Name, MyRs.Fields(i).Name
            Next i
' -- End of questionable section

        End If
    Next

Any ideas here?

--
David Wier
http://www.aspexpress.com
Home of ASP Express - the best ASP text editor in the Galaxy

Quote:
> I successfully created a form that, after choosing a database, will fill a
> combobox with the TableNames...
> I also created another combobox so that, when you clicked on a table name,
> will list the field names.

> Then, I tried to do the same thing with a Treeview, except, list them all
at
> once, when the database (Access) is chosen. However, I can't even get past
> the tablename part -- the project freezes & crashes my computer....Here's
> the code I'm using:
>         strDB = cdledit.FileTitle
>         txtDatabase.Text = strDB
>         Data1.DatabaseName = cdledit.FileName
>         Set db = OpenDatabase(txtDatabase.Text)
>         Tv1.Nodes.Add , , "RootNode", strDB

>         cboTables.Clear
>         For Each td In db.TableDefs
>             strTablename = td.Name

>             If Mid(strTablename, 1, 4) <> "MSys" Then
>                 cboTables.AddItem strTablename
> 'Up to the above statement, it works fine - the following line is where it
> freezes:
>                 Tv1.Nodes.Add "RootNode", tv1Child, strtablename,
> strTablename
>             End If

>          Next
> If anyone can help or give me a hint of why it's happening, please let me
> know.
> David Wier



Thu, 28 Feb 2002 03:00:00 GMT  
 Using a Treeview to List Tables & Fields

and posted to comp.lang.basic.visual.database:

Quote:

>Then, I tried to do the same thing with a Treeview, except, list them all at
>once, when the database (Access) is chosen. However, I can't even get past
>the tablename part -- the project freezes & crashes my computer....Here's
>the code I'm using:
>        strDB = cdledit.FileTitle
>        txtDatabase.Text = strDB

David try this:

    Dim tbl As TableDef
    Dim fld As Field
    Dim nodX As Node

    For Each tbl In db.TableDefs
        If Mid(tbl.Name, 1, 4) <> "MSys" Then
            Set nodX = TreeView1.Nodes.Add(, , tbl.Name, tbl.Name)
            nodX.EnsureVisible
            For Each fld In tbl.Fields
                Set nodX = TreeView1.Nodes.Add(tbl.Name, tvwChild,
tbl.Name & "." & fld.Name, fld.Name)
            Next
        End If
    Next



Fri, 01 Mar 2002 03:00:00 GMT  
 Using a Treeview to List Tables & Fields
Thanks a bunch - that works great - and now I understand it.
--
David Wier



Quote:

> and posted to comp.lang.basic.visual.database:

> >Then, I tried to do the same thing with a Treeview, except, list them all
at
> >once, when the database (Access) is chosen. However, I can't even get
past
> >the tablename part -- the project freezes & crashes my computer....Here's
> >the code I'm using:
> >        strDB = cdledit.FileTitle
> >        txtDatabase.Text = strDB

> David try this:

>     Dim tbl As TableDef
>     Dim fld As Field
>     Dim nodX As Node

>     For Each tbl In db.TableDefs
>         If Mid(tbl.Name, 1, 4) <> "MSys" Then
>             Set nodX = TreeView1.Nodes.Add(, , tbl.Name, tbl.Name)
>             nodX.EnsureVisible
>             For Each fld In tbl.Fields
>                 Set nodX = TreeView1.Nodes.Add(tbl.Name, tvwChild,
> tbl.Name & "." & fld.Name, fld.Name)
>             Next
>         End If
>     Next



Mon, 04 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. showing field data from a table using a treeview control

2. List SQL Server Tables & Fields

3. VB6 & Access - howto get list of tables & list of fields in a table

4. Testing for table existence & listing available tables

5. How to Compare Tables, Fields, & Field Properties

6. Copy fields from record in table A to record in table B using VBA

7. Subtracting qty from a field on one table from qty used on another table

8. using table field names after table connect

9. treeview & listview, slow directory listing

10. Create new fields in a table based off of fields in another table

11. Create new field in existing table exactly like field in second table

12. updating fields in table from field in another table

 

 
Powered by phpBB® Forum Software