DAO: CopyTableDef() ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

has someoned done already a 1:1 copy routine to to copy the exact tabe frome
one db to another ? like:

Function CopyTableDef (strDBSourceName$, strDBDestName$, strTableName$)

I have the impression that ".CreateField(fldSource.name, fldSource.Type,
fldSource.Size)" simply would not do a complete job......
 
The function is built into VBA, there are a couple of ways to go about it,
but I always use

DoCmd.TransferDatabase (...)

If you want the field names only, not the data, enter "True" for the
Structure Only argument.

Nick
 
the bizzar thing is: when I loop through the new table to fill in data, at
the 9th record it says : Runtime error -2147217887 Textfield of length null
not allowed :-(
 
If the goal is to make a backup copy of a table into another database, this
should do it:

Private Function BackupTable(dbLocal As DAO.Database, dbBackup As
DAO.Database, _
strTable As String, rsError As DAO.Recordset, strErrMsg As String) As
Boolean
On Error GoTo Err_Handler
'Purpose: Create a copy of this table into the target database.
'Arguments: dbLocal = this database.
' dbBackup = the backup database.
' strTable = name of the table to be backed up.
' rsError = the error table in the backup database to append
error messages to.
' strErrMsg = string to append error messages to if the error
messages can't be written.
Dim strSql As String

DoCmd.Echo True, "Backing up table: " & strTable 'Display the name of
the table.
strSql = "SELECT * INTO [" & strTable & "] IN """ & dbBackup.Name & """
FROM [" & strTable & "];"
dbLocal.Execute strSql, dbFailOnError
BackupTable = True

Exit_Handler:
Exit Function

Err_Handler:
Call WriteError(dbBackup, rsError, strTable, acTable, Err.Number,
Err.Description, strErrMsg)
Resume Exit_Handler
End Function

There's a more complete version of this backup code at:
http://allenbrowne.com/unlinked/Backup.txt
 
Back
Top