Delete Tables in External Database (1 Viewer)

keawee

Registered User.
Local time
Today, 08:07
Joined
Jul 8, 2003
Messages
16
I would like delete all the tables in other database

hello,

I would like your help about my problem.

I would like to delete all the tables in other database. I have try this but it doesn't work. I have two tables in ma database outwards the system tables and my code is block on the line Do.Cmd because he didn't find this two tables !!. Do you can help me.

Code:
..
folder = Application.CurrentProject.Path

Set db = OpenDatabase(folder& "\RI Account.mdb")

For i = 0 To db.TableDefs.Count
If db.TableDefs(i).Name Like "MSys*" Then
Else
DoCmd.DeleteObject acTable, db.TableDefs(i).Name
End If
Next i
..

Thanks

Keawee
 

Tim K.

Registered User.
Local time
Today, 08:07
Joined
Aug 1, 2002
Messages
242
Change this line from

DoCmd.DeleteObject acTable, db.TableDefs(i).Name

to

db.TableDefs.Delete db.TableDefs(i).Name

and make sure to delete all relationships before doing this.

:)
 

keawee

Registered User.
Local time
Today, 08:07
Joined
Jul 8, 2003
Messages
16
Hello Tim K and thank you for your answer.

I have replace my code by your code like this

Code:
For i = 0 To db.TableDefs.Count
If db.TableDefs(i).Name Like "MSys*" Then
Else
db.TableDefs.Delete db.TableDefs(i).Name
End If
Next i

Access launch me a code error, number 3265. The element is not find in this collection.

Do you have an idea to resolve this problem ?.

Thanks You

Keawee
 

Tim K.

Registered User.
Local time
Today, 08:07
Joined
Aug 1, 2002
Messages
242
Try this out.

Code:
...
Dim tdf As Object

folder = Application.CurrentProject.Path

Set db = OpenDatabase(folder& "\RI Account.mdb")

For Each tdf In db.TableDefs
    If Left(tdf.Name, 4) <> "MSys" Then
        db.TableDefs.Delete tdf.Name
    End If
Next tdf
...

:)
 

keawee

Registered User.
Local time
Today, 08:07
Joined
Jul 8, 2003
Messages
16
Thanks you Tim k for your advice and your help,

Have a nice day or night !! ;-)

Keawee
 

Users who are viewing this thread

Top Bottom