
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