Results 1 to 2 of 2

Thread: 2 Backend Problems...

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2003
    Posts
    38

    2 Backend Problems...

    I had 2 database problem
    I using access as backend in VB. Using ADO programing

    1) I want to check how many tables are thier in my database of access.Using some query or coding

    2) I want to copy a table structure to new table in access.Using query or coding.I used create table tname as select * from table but not working.

    Thanks lot

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    1)
    This sample lists all tables to a listbox. modify it to suite your needs.

    VB Code:
    1. Option Explicit
    2.  
    3. 'Add a reference to Microsoft ADO Ext. X.X For DLL And Security
    4.  
    5. Private Sub Form_Load()
    6.     ListTables
    7. End Sub
    8.  
    9. Sub ListTables()
    10.     Dim cat As New ADOX.Catalog
    11.     Dim tbl As ADOX.Table
    12.     ' Open the catalog
    13.     cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\Test.mdb;"
    14.     List1.Clear
    15.    
    16.     For Each tbl In cat.Tables
    17.         If UCase(tbl.Type) = "TABLE" Then List1.AddItem tbl.Name
    18.     Next tbl
    19.     Set cat = Nothing
    20.     Set tbl = Nothing
    21. End Sub




    2)
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim cat As ADOX.Catalog
    3.     Dim tbl As ADOX.Table
    4.    
    5.     Dim sDBFrom As String
    6.     Dim sDBTo As String
    7.     Dim sql As String
    8.     Dim cnn As New ADODB.Connection
    9.    
    10.     sDBFrom = "D:\TEST\From.mdb"
    11.     sDBTo = "D:\TEST\To.mdb"
    12.    
    13.    
    14.     'check to see if the database exist. if not create it.
    15.     If Dir(sDBTo) = "" Then
    16.         'database does not exist, make the database
    17.         Set cat = New ADOX.Catalog
    18.         cat.Create "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBTo
    19.         Set cat = Nothing
    20.     End If
    21.    
    22.     'setup db connection
    23.     cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBFrom
    24.     Set cat = New ADOX.Catalog
    25.     Set cat.ActiveConnection = cnn
    26.  
    27.     'copy all the tables using SQL and Execute
    28.     For Each tbl In cat.Tables
    29.         Debug.Print tbl.Name & "  :  " & tbl.Type
    30.         'Make sure this is a table and not a query / view
    31.         If UCase(tbl.Type) = "TABLE" Then
    32.             'make sure that you do not try to create the system tables,
    33.             'cause they will already be in the db
    34.             If UCase(Left(tbl.Name, 4)) <> "MSYS" Then
    35.                 sql = "SELECT * INTO " & tbl.Name & " IN '" & sDBTo & "' FROM " & tbl.Name
    36.                 cnn.Execute sql
    37.             End If
    38.         End If
    39.     Next tbl
    40.    
    41.     'close the connection
    42.     Set cat = Nothing
    43.     Set cnn = Nothing
    44.     MsgBox "Import finished", vbInformation
    45. End Sub
    -= a peet post =-

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