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 http://www.codeoftheweek.com/vbtraining.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
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 questions@codeoftheweek.com
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 dbissues@codeoftheweek.com
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.
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" Else MsgBox "Table not copied" End If
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: http://www.codeoftheweek.com/membersonly/bi/0107.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html