View Single Post
  #3 (permalink)  
Old 10-23-05, 16:02
CyberLynx CyberLynx is offline
Stuck on my opinions...
 
Join Date: Nov 2003
Posts: 1,487
Just like anything else in Microsoft Access, you can do almost any one thing about six different ways. It all depends upon which environment or environments you want to play in. Here is a little function using ADOX that will do the task at hand:

NOTE:
You will need to Reference the Microsoft ADO Ext for DDL and Security (ADOX) Library.

Code:
Public Function RenameColumn(ByVal StrgDB_Name As String, StrgTableName As String, _
				StrgOldColumnName As String, StrgNewColumnName As String) As Boolean
   On Error GoTo Err_RenameColumn
 
   'Create a Catalog object
   Dim Cat As ADOX.Catalog
   Set Cat = New ADOX.Catalog
   Cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & StrgDB_Name
 
   'Create a table object
   Dim Tbl As ADOX.Table
   Set Tbl = New ADOX.Table
   Set Tbl = Cat.Tables(StrgTableName)
   Tbl.Columns(StrgOldColumnName).Name = StrgNewColumnName
 
   'Return that the function was Successfull.
   RenameColumn = True
 
Exit_RenameColumn:
   'Clean up
   Set Cat = Nothing
   Set Tbl = Nothing
   Exit Function
 
Err_RenameColumn:
	MsgBox "There was an Error while Renaming the Table Column [" & StrgOldColumnName & "] to [" & _
	StrgNewColumnName & "] within the Table named [" & StrgTableName & "] which is located in the " & _
	StrgDB_Name & " Database.", vbCritical, "Column Rename Error"
	GoTo Exit_RenameColumn
End Function

.
__________________
Environment:
Self Taught In ALL Environments.....And It Shows!

Reply With Quote