none
Copy and Rename a Table in MS Access using VB RRS feed

  • Question

  • Hi all,

    I am trying to copy an existing MS Access table (with its structure only), and rename the original to some other name.

    Could someone share a piece of code that can perform the above operation, in VB?

    Thanks for any assistance,

    MNRaghu

    Saturday, October 15, 2005 5:19 AM

All replies

  • I think you have not posted in the rigth forum.....
    Saturday, October 15, 2005 10:19 AM
  • Sorry, it was a mistake. I have posted the issue in visual basic forum now.

    Thanks,
    MNRaghu
    Sunday, October 16, 2005 8:37 AM
  • Here's one way to copy a table. Just delete the contents of either table afterwards.


    Dim sSQL As String = "SELECT * INTO " & sNewTableName & " FROM (" & sOldTableName & ")"
    DoExecuteNonQuery(sSQL)

    Public Function DoExecuteNonQuery(ByVal sConnect As String, ByVal sqlCommand As String) As Boolean
       Dim cn As OleDbConnection = New OleDbConnection(sConnect)
       cn.Open()
       Dim cm As New OleDbCommand(sqlCommand, cn)
       cm.CommandText = sqlCommand
       cm.ExecuteNonQuery()
       cm.Dispose()
       cm = Nothing
       cn.Close()
       cn.Dispose()
       return True
    End Function


     


    I also do this directly using ADOX, but it's complex. ADOX is the only way I know of to create a table from scratch.

    ---MikeB

    Monday, October 17, 2005 4:07 PM
  • Mike,

    Thanks for the reply.

    That's really useful.

    MNRaghu
    Sunday, October 23, 2005 6:20 AM