I have an ms access db with text field that needs to be changed from a column size of 50 to the maximum value of 255.
Can i write a script to do this change? I want to just give the script to the dba so he can run.
Please and thanks.
I spent a little time trying to do it, but was not able to. You will probably need to use DAO and the TablDef object. Here is some code I wrote to add an AutoNumber field to a tabledef. It might give you some ideas. My feeling is that unless you are doing this alot, then it is to much bother.
Public Function AddIDField(strTableName As String, _
strFieldName As String) As Boolean
'Description : Automatically number records, beginning at 1, by adding an autonumber
' field to the table.
'Parameters : strTableName The name of the table to add the field to
' strFieldName The name to give to the AutoNumber field
'Return : Boolean. Returns whether or not the field was added successfully.
'03/18/05 Original function.
Dim tdfIncoming As DAO.TableDef
Dim dbCurrent As DAO.Database
Dim fldAutoNumber As DAO.Field
Dim idxPrimary As DAO.Index
On Error GoTo AddFieldError
'Set a reference to the table and create the new field
Set dbCurrent = CurrentDb()
Set tdfIncoming = dbCurrent.TableDefs(strTableName)
Set fldAutoNumber = tdfIncoming.CreateField(strFieldName, dbLong)
Set idxPrimary = tdfIncoming.CreateIndex
'Now set the field to an auto number field
fldAutoNumber.Attributes = dbAutoIncrField
'Now append the new field to the table definition
'Now create the Primary Index
idxPrimary.Primary = True
idxPrimary.Name = "Whatever"
'Now append the Primary Index
'Set the falg to indicate the field was added successfully
AddIDField = True
Set tdfIncoming = Nothing
Set fldAutoNumber = Nothing
Set idxPrimary = Nothing
Set dbCurrent = Nothing
AddIDField = False