Hello, hope I've picked the right forum here!
I need to make an exact copy of a table, and rename it something similar, just without any of the data. I'm using Access 2K here.
I am basically trying to automate the process where-by a user manually selects a table, copies it, and then clicks on paste. When they click on paste, they get the options to Paste: Structure Only, Structure and Data, or Append Data To Existing Table. I want to replicate choosing option Structure Only.
So far I've worked out how to create a table with the same fields, field types, and sizes, but I need to make sure I am also getting any indexes, and PKs.
Here is my code so far:
I realise I'm not tidying up at the end - that's the least of my concerns!!!
I did wonder about simply using a make table query, but will the indexes and keys be replicated?
Thanks for any help anyone can give me!!
Tom
I need to make an exact copy of a table, and rename it something similar, just without any of the data. I'm using Access 2K here.
I am basically trying to automate the process where-by a user manually selects a table, copies it, and then clicks on paste. When they click on paste, they get the options to Paste: Structure Only, Structure and Data, or Append Data To Existing Table. I want to replicate choosing option Structure Only.
So far I've worked out how to create a table with the same fields, field types, and sizes, but I need to make sure I am also getting any indexes, and PKs.
Here is my code so far:
Code:
Function fncCopyStructure(strTable As String, strNewTable As String)
On Error Resume Next
'This function takes a table, opens it up (using ADOX), and then recreates the table with the defined new name.
'It matches with name, field type and defined size
Dim tblNew As New ADOX.Table ' new table created
Dim tblTemp As ADOX.Table ' Existing table to be copied
Dim colTemp As ADOX.Column ' Column collection
Dim catTemp As New ADOX.Catalog ' catalog - to open tables collection
catTemp.ActiveConnection = CurrentProject.Connection
Set tblTemp = catTemp.Tables(strTable)
tblNew.Name = strNewTable
For Each colTemp In tblTemp.Columns
tblNew.Columns.Append colTemp.Name, colTemp.Type, colTemp.DefinedSize
Next
catTemp.Tables.Append tblNew
End Function
I realise I'm not tidying up at the end - that's the least of my concerns!!!
I did wonder about simply using a make table query, but will the indexes and keys be replicated?
Thanks for any help anyone can give me!!
Tom