Copying the structure of a table to a new table 
Author Message
 Copying the structure of a table to a new table

Hi,

Is there an easy way via VBA code to copy the structure (not the data) of
a table into a new table?  I don't want to have to copy the entire
existing table and then run a DELETE query on it.  Seems like there
should be an easier way.  Any ideas?

Bill

***********************************************************************
To reply to me, please remove one of the 'X's  from my email address.
***********************************************************************



Thu, 15 Mar 2001 03:00:00 GMT  
 Copying the structure of a table to a new table
Try this function.

'************ Code Start *************
Function fCopyTableStruct(strTableName As String, _
                                        strNewName As String) _
                                        As Boolean
Dim db As Database, tdf As TableDef
Dim tdfNew As TableDef

    On Error GoTo Err_handler
    Set db = CurrentDb
    Set tdf = db.TableDefs(strTableName)
    On Error Resume Next
    Set tdfNew = db.TableDefs(strNewName)
    If Err Then

        DoCmd.TransferDatabase acExport, "Microsoft Access", _
                                                        db.Name, _
                                                        acTable, _
                                                        strTableName, _
                                                        strNewName, _
                                                        True
        db.TableDefs.Refresh
        fCopyTableStruct = True
    Else
        On Error GoTo 0
    End If
Exit_Here:
    Set tdf = Nothing
    Set db = Nothing
    Exit Function
Err_handler:
    fCopyTableStruct = False
    Resume Exit_Here
End Function
'************** Code End **************

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

:Hi,
:
:Is there an easy way via VBA code to copy the structure (not the data) of
:a table into a new table?  I don't want to have to copy the entire
:existing table and then run a DELETE query on it.  Seems like there
:should be an easier way.  Any ideas?
:
:Bill
:
:***********************************************************************
:To reply to me, please remove one of the 'X's  from my email address.
:***********************************************************************



Thu, 15 Mar 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Copying the structure of one Access table to a new Access table

2. HowTo Copy a Recordset from a Table to an identically structured table

3. Copy external data structure to new table

4. Copying table definition to create new table

5. copy table structure

6. Copying table structures in code

7. Newbie: How to copy Table structure?

8. Copy Foxpro 2.6 table structure

9. Creating .MDB in ADO; copying a table structure

10. How to copy structure of a table to another database

11. Copying Table structures

12. Newbie: How to copy Table structure?

 

 
Powered by phpBB® Forum Software