Change field size of Text data type fields in Microsoft Access
I need to be able to go through my Access database in Design view and change all the Data type fields that are 'Text' to a Field Size of about 120. Is there a macro I can get in Access to do this?
Sub ChangeFieldSize(sTable As String, iSize As Integer)
Dim fld As DAO.Field, tdf As DAO.TableDef
For Each tdf In CurrentDb.TableDefs
If tdf.Name = sTable Then
For Each fld In tdf.Fields
If fld.Type = 10 Then
CurrentDb.Execute _
"Alter table " & sTable & " alter column " & fld.Name & " TEXT(" & iSize & ")"
End If
Next
End If
Next
Dim fld As DAO.Field, tdf As DAO.TableDef, TName as string
For Each tdf In CurrentDb.TableDefs
If (Not Tdf.Name Like "msys*") And (Not Tdf.Name = "~*") Then
For Each fld In tdf.Fields
If fld.Type = 10 Then
CurrentDb.Execute _
"Alter table " & sTable & " alter column " & fld.Name & " TEXT("120")"
End If
Next
End If
Next
Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.
Public Sub changeAllTextFields(iNewLe
Dim T As TableDef
Dim F As Field
For Each T In CurrentDb.TableDefs
For Each F In T.Fields
If F.Type = 10 Then
End If
Next
Next
End Sub
Now ... changing the field size ... haven't found that piece yet! Maybe this will get you started ...