Alter table

timothyl

Registered User.
Local time
Today, 12:17
Joined
Jun 4, 2009
Messages
92
New to writing sql. From my books and on line search this seems like it would work.

ALTER TABLE tblparts1 CHANGE HCPCRow1 Hcpc

get syntac error, CHANGE , have tried: change Column, Modify, no luck. Would some one tell me the proper statment.

Thanks Tim
 
Thank you rainman89. Rainman89 if I have more then one column is it
ALTER TABLE mytable RENAME COLUMN mycolumn1, mycolumn2 TO new1, new2

Or

ALTER TABLE mytable RENAME COLUMN mycolumn1 TO new, RENAME COLUMN mycolumn2 TO new2
 
I believe it would be like this

ALTER TABLE mytable RENAME COLUMN (mycolumn1 TO new1, mycolumn2 TO new2)

but i have not tried it
 
Turns out Access dose not support RENAME, I found this on another fourm, works well

Sub RenameField(strTableName As String, _
strFieldFrom As String, _
strFieldTo As String)

Dim dbs As DAO.Database
Dim tDef As DAO.TableDef
Dim fDef As DAO.Field

Set dbs = CurrentDb()
Set tDef = dbs.TableDefs(strTableName)
Set fDef = tDef.Fields(strFieldFrom)

fDef.Name = strFieldTo

Set fDef = Nothing
Set tDef = Nothing
Set dbs = Nothing

'Then just call it like: RenameField "tblRenCol","Jeff","Jeffrey"

End Sub
 
vb i understand a bit. Can i just copy that code into a button?
 
No copy the code, hit alt and f11 then paste. Under a button go

RenameField "myTableName","ColumnName","NewColumnName"

RenameField "myTableName","ColumnName2","NewColumnName2"
ect
if you have trouble post back. Tim
 
Private Sub Command1_Click()
RenameField "Table1", "Field1", "Jeffrey"


End Sub

This is my code in the button, table1 is my actual table name and field1 is what my field name is and jeffry is what i want it to be. id i click the button it gives me a compile error on the botled line.

Sub RenameField(strTableName As String, _
strFieldFrom As String, _
strFieldTo As String)

Dim dbs As DAO.Database
Dim tDef As DAO.TableDef
Dim fDef As DAO.Field

Set dbs = CurrentDb()
Set tDef = dbs.TableDefs(strTableName)
Set fDef = tDef.Fields(strFieldFrom)

fDef.Name = strFieldTo

Set fDef = Nothing
Set tDef = Nothing
Set dbs = Nothing

'Then just call it like: RenameField "tblRenCol","Jeff","Jeffrey"

End Sub
 
Sorry it works i see it does it when i press the button for the seccond time coz it does not contain the origenal field name any more. Tnx alllllot
 
I dont know if this is helpful, but you could make three text boxes MyTable, MyFieldName and MyNewFieldName then go

RenameField "" & Me.MyTable & "", "" & Me.TableFieldName & "", "" & Me.MyNewFieldName &""

anyway glade to see you got it sorted out. Tim
 
Jip this is what i wanted to do. tnx allot for all the help.
 

Users who are viewing this thread

Back
Top Bottom