Jan 10, 2002 #1 briglass Programmer Dec 4, 2001 179 GB I'm trying to rename table RED in apple.mdb to RED1 using SQL commands issued by visual basic. Or, is there an easier way with ADO and visual basic? Thanks, Brian
I'm trying to rename table RED in apple.mdb to RED1 using SQL commands issued by visual basic. Or, is there an easier way with ADO and visual basic? Thanks, Brian
Jan 10, 2002 1 #2 tlbroadbent MIS Mar 16, 2001 9,982 US In VBA you can use the DoCMD.Rename method. DoCmd.Rename "OldName", acTable, "NewName" Terry L. Broadbent Programming and Computing Resources http://tlbroadbent.home.attbi.com/prog.htm Upvote 0 Downvote
In VBA you can use the DoCMD.Rename method. DoCmd.Rename "OldName", acTable, "NewName" Terry L. Broadbent Programming and Computing Resources http://tlbroadbent.home.attbi.com/prog.htm
Jan 10, 2002 Thread starter #3 briglass Programmer Dec 4, 2001 179 GB thanks, i'll try that. but is there an SQL method? Upvote 0 Downvote
Jan 11, 2002 #4 Kubilus1 IS-IT--Management Apr 25, 2001 99 US SQL Books online gives the following syntax to rename objects in T-SQL: sp_rename [@objname =] 'object_name', [@newname =] 'new_name' [, [@objtype =] 'object_type'] object_name-> Current name of the object new_name-> new name for the object object_type -> Says wether you are renaming a column or object. For your purposes, this can be ignored. Matt Upvote 0 Downvote
SQL Books online gives the following syntax to rename objects in T-SQL: sp_rename [@objname =] 'object_name', [@newname =] 'new_name' [, [@objtype =] 'object_type'] object_name-> Current name of the object new_name-> new name for the object object_type -> Says wether you are renaming a column or object. For your purposes, this can be ignored. Matt
Jan 11, 2002 #5 Kubilus1 IS-IT--Management Apr 25, 2001 99 US I should add, this code is for SQL7. I am not sure how compatible it is for jet SQL, as in Access. It should be worth a shot though. Upvote 0 Downvote
I should add, this code is for SQL7. I am not sure how compatible it is for jet SQL, as in Access. It should be worth a shot though.
Jan 11, 2002 Thread starter #6 briglass Programmer Dec 4, 2001 179 GB Thanks for you help, but I'm still having problems. I have tried the SQL script "RENAME TABLE happy TO nothappy;" but that didn't work. I also tried dbTable.Name = "happy" but that didn't work. **Is there any way to change the name of a table that is in an Access 97 database using visual basic 6?** Thanks, Brian Upvote 0 Downvote
Thanks for you help, but I'm still having problems. I have tried the SQL script "RENAME TABLE happy TO nothappy;" but that didn't work. I also tried dbTable.Name = "happy" but that didn't work. **Is there any way to change the name of a table that is in an Access 97 database using visual basic 6?** Thanks, Brian
Jan 11, 2002 #7 tlbroadbent MIS Mar 16, 2001 9,982 US I don't know of any SQL command to rename a table. You could use the following to rename a table in two steps but I don't recommend it. Select * into NewName From OldName Drop Table OldName Of course, you will have recreate the primary keys, relationships, indexes, etc. Here is another solution using DAO as "Docmd.Rename" may not be available in VB6. Dim db As Database Set db = OpenDatabase("C:\SomePath\Your.mdb" db.TableDefs("OldTable".Name = "NewTable" db.Close Terry L. Broadbent Programming and Computing Resources http://tlbroadbent.home.attbi.com/prog.htm Upvote 0 Downvote
I don't know of any SQL command to rename a table. You could use the following to rename a table in two steps but I don't recommend it. Select * into NewName From OldName Drop Table OldName Of course, you will have recreate the primary keys, relationships, indexes, etc. Here is another solution using DAO as "Docmd.Rename" may not be available in VB6. Dim db As Database Set db = OpenDatabase("C:\SomePath\Your.mdb" db.TableDefs("OldTable".Name = "NewTable" db.Close Terry L. Broadbent Programming and Computing Resources http://tlbroadbent.home.attbi.com/prog.htm