|
-
Jun 1st, 2002, 04:19 PM
#1
Extracting table names and field names from Access 2000 db via code
This has to be possible, but can't suss it at all
-
Jun 1st, 2002, 05:58 PM
#2
-= B u g S l a y e r =-
VB Code:
'Add a reference to Microsoft ADO Ext. X.X For DLL And Security
'Add a reference to Microsoft ActiveX Data Objects X.X Library
Option Explicit
Private cat As ADOX.Catalog
Private tbl As ADOX.Table
Private cnn As New ADODB.Connection
Private col As New Column
Private Sub Command1_Click()
Set cat = New ADOX.Catalog
Set tbl = New ADOX.Table
'setup db connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB"
Set cat.ActiveConnection = cnn
'loop through all tables, and all fields in each table.
For Each tbl In cat.Tables
Debug.Print tbl.Name
For Each col In tbl.Columns
Debug.Print vbTab & vbTab & col.Name
Next col
Next tbl
'close the connection
cnn.Close
Set cnn = Nothing
End Sub
should get u going Jello
-
Jun 1st, 2002, 06:05 PM
#3
Hey thanks Peet .... that should do the trick cool...
-
Jun 1st, 2002, 06:23 PM
#4
-= B u g S l a y e r =-
-
Jun 1st, 2002, 08:28 PM
#5
She's doing a few for the latest TT party next friday ... of course she would never think of competing with Ye Olde Viking Avatars...
Just plowing through your code post at the moment. Thanks again peet a real life saver, have to demo a beta early next week
-
Jun 2nd, 2002, 12:35 AM
#6
Addicted Member
You can also query the system tables in the database. To view them, goto Tool / Options in Access and check the "System objects" in the "Show" group.
To get a recordset of all tables, you can issue the SQL statement: SELECT [Name] FROM [MSysObjects] WHERE (type = 1)
-
Jun 2nd, 2002, 02:17 PM
#7
Thanks Jason unfort need to do it via code.
OKie dokie Peet that worked a treat got the following happening
a) Connect to mdb
b) Combo drop down of files
c) User selects a file
d) Field names, type, and size displayed.
Two further problems.
1) After the user selects a file, it would appear that l have to loop through the table list again to get Tbl.Name = combo select, in order to display the field details. Is there a better way of doing this.
2) Field types are coming back as integers, e.g 130 = text. Not a huge problem but anyway of translating it without resorting to a Select Case statement and manually translating it.
-
Jun 3rd, 2002, 01:31 AM
#8
-= B u g S l a y e r =-
morning Jethro,
1) cant think, and don know, of a better/smarter way to do it
2) I use select case, have not found a better way. There are built
in const. for field type when using DAO.
VB Code:
Private Function GetVarType(dbFieldTypeConst As Long) As String
Select Case dbFieldTypeConst
Case dbText
GetVarType = "String"
Case dbBoolean
GetVarType = "Boolean"
Case dbBigInt
GetVarType = "LongInt"
Case dbDate
GetVarType = "String"
Case dbDouble
GetVarType = "Double"
Case dbInteger
GetVarType = "Integer"
Case dbLong
GetVarType = "Long"
Case dbMemo
GetVarType = "String"
Case dbSingle
GetVarType = "Single"
Case dbText
GetVarType = "String"
Case Else
GetVarType = "String"
End Select
End Function
use that in an old app I'v made, there are probably const. for the ADOX returned types aswell, I'd use them. (don't know what they
are though )
-
Jun 3rd, 2002, 09:24 PM
#9
Thanks again oh great viking coding god
Okie dokie .... expect more questions....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|