Link to home
Start Free TrialLog in
Avatar of al4629740
al4629740Flag for United States of America

asked on

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?
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Iterating the fields is easy:


Public Sub changeAllTextFields(iNewLength As Integer)
    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 ...
Avatar of Rey Obrero (Capricorn1)
try this codes, place the codes in a module

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

End Sub
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
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yep...that's gotter Cap.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of al4629740

ASKER

Very Good Guys.  Finally got to try it.  : )