Visual Basic Code of the Week (COTW)
Issue #107
Online Version at (paid subscribers only)
All content and source code is Copyright (c) 1999 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

Issue topic: Copying table structures from one database to another

Six months of VB Training for only $49.99

Want to get up to speed on the latest Visual Basic programming? Includes Visual Basic 6 and Visual InterDev 6. Check out our training programs at

Get paid to surf the web!

If you would like to get paid for surfing the web, jump to


In this Issue

In this issue we discuss how to copy a database table structure using some standard SQL instructions.

If you have any questions about using this module, let us know at


The basDatabase module contains a single function that copies a the structure of a database table into another database name. It accomplishes this by using the INTO .. IN SQL clause. There is a topic in the Jetsql35.hlp that comes with Visual Basic 5.0 called "SELECT...INTO" that fully discusses the various options on this powerful statement. This routine could easily be extended to do database backups of tables. If you are interested in this, drop us an email at


Public Function CopyTableStructureToNewDB(sSourceDB As String, sDestDB As String, _
                                        sSourceTable As String, _
                                        sDestinationTable As String) As Boolean

This method will copy the database structure from one database to another database. The destination database must already exist for this method to succeed. If you need to create the destination database you can use the CreateDatabase method which is part of the Microsoft DAO routines.

Sample Usage

The below sample copies the table structure of the POS table in the database e:\temp\pos.mdb to POS in database e:\temp\posbackup.mdb

    If CopyTableStructureToNewDB("e:\temp\pos.mdb", "e:\temp\posbackup.mdb","pos", "pos") Then
        MsgBox "Table copied"
        MsgBox "Table not copied"
    End If

Source Code

To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address:

This document is available on the web

Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

Get paid to surf the web!

If you would like to get paid for surfing the web, jump to

Other links

Contact Information

C&D Programming Corp.
PO Box 20128
Floral Park, NY 11002-0128
Phone or Fax: (212) 504-7945