Hi i found this code in this forum courtesy of Lory from Singapore (thanks!) \r\n \r\nPrivate Sub Command1_Click() \r\nOn Error GoTo CSErr \r\n \r\nDim i As Integer \r\nDim tblTableDefObj As TableDef \r\nDim fldFieldObj As Field \r\nDim tdf As TableDef \r\nDim fld As Field \r\n \r\nDim CurrentDatabase As Database \r\nDim FTableName As String \r\nDim ToTableName As String \r\n \r\n\'search to see if table exists \r\n \r\nSet CurrentDatabase = DBEngine(0).OpenDatabase(App.Path + "\\data1.mdb") \r\nSet tblTableDefObj = CurrentDatabase.CreateTableDef() \r\n \r\nFTableName = "Hang" \'table you want to copy structure \r\nToTableName = "Copy_of_Hang" \' Name for New table \r\ntblTableDefObj.Name = ToTableName \r\n \r\n\'create the fields \r\nFor i = 0 To CurrentDatabase.TableDefs(FTableName).Fields.Count - 1 \r\nSet fld = CurrentDatabase.TableDefs(FTableName).Fields(i) \r\nSet fldFieldObj = CurrentDatabase.TableDefs(FTableName).CreateField(fld.Name, fld.Type, fld.Size) \r\ntblTableDefObj.Fields.Append fldFieldObj \r\nNext \r\n \r\n\'append the new table \r\nCurrentDatabase.TableDefs.Append tblTableDefObj \r\n \r\nExit Sub \r\nCSErr: \r\n\'Err trap \r\n \r\nEnd Sub \r\n \r\n \r\nOk, so this works (but its too long), is there any short method to this? and how can I delete the table in case using this same code?
\r\n \r\n\r\n
\r\n
\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n \r\n
\r\n __________________ \r\n angel bear \r\n \r\n"Don\'t go there!"\r\n
Hi i found this code in this forum courtesy of Lory from Singapore (thanks!)
Private Sub Command1_Click()
On Error GoTo CSErr
Dim i As Integer
Dim tblTableDefObj As TableDef
Dim fldFieldObj As Field
Dim tdf As TableDef
Dim fld As Field
Dim CurrentDatabase As Database
Dim FTableName As String
Dim ToTableName As String
'search to see if table exists
Set CurrentDatabase = DBEngine(0).OpenDatabase(App.Path + "\data1.mdb")
Set tblTableDefObj = CurrentDatabase.CreateTableDef()
FTableName = "Hang" 'table you want to copy structure
ToTableName = "Copy_of_Hang" ' Name for New table
tblTableDefObj.Name = ToTableName
'create the fields
For i = 0 To CurrentDatabase.TableDefs(FTableName).Fields.Count - 1
Set fld = CurrentDatabase.TableDefs(FTableName).Fields(i)
Set fldFieldObj = CurrentDatabase.TableDefs(FTableName).CreateField(fld.Name, fld.Type, fld.Size)
tblTableDefObj.Fields.Append fldFieldObj
Next
'append the new table
CurrentDatabase.TableDefs.Append tblTableDefObj
Exit Sub
CSErr:
'Err trap
End Sub
Ok, so this works (but its too long), is there any short method to this? and how can I delete the table in case using this same code?
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe