Discussion Locked

How do I copy an Access table with VB?

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I need to be able to copy the structure of an existing Access table in VB, checking to see if a couple of columns exist, if not, creating them, and saving them with a new name. Is this possible programatically?

3 replies

by politot

Presuming you're doing this via VBA code in your Access Database, use the "DoCmd.CopyObject". But to make sure you don't get "system" tables (hidden ones created by Access), use:
Dim t as TableDef
For Each t In CurrentDb.TableDefs
If t.Attributes = 0 Then 'zero = user table
DoCmd.CopyObject sBUTName, "", acTable, t.Name
End If
Next

You can theoretically use this to copy any Access object (table, query, form, report, etc) within a database or to a different database file.

This discussion is closed to new replies.