aziz rasul
05-22-2008, 02:55 AM
I have a table that has 248 text fields wrt a spec that I have to comply with. There is no data in the table thus far.
When the original table was designed, the field lengths were set to 255 and we now need to set them to 150 or perhaps a different value.
I wrote some code in a test db so that the field data lengths could be reduced. The code worked.
I transferred the code to the actual db. The code will work up to a small number of fields and then debugs to run time error 3190 i.e. too many fields. If I compact\repair the db the code then moves on further doing more fields than before and so on. Hence only by compacting\repairing the db about 20 times did I get all the fields changed.
The question is, WHY. Here's the main snippet of code: -
For Each tdf In CurrentDb.TableDefs
If tdf.Name = Me.txtTableName Then
For Each fld In tdf.Fields
If DataType(fld.Type) = "Text" Then
CurrentDb.Execute "ALTER TABLE [" & strTable & "] ALTER COLUMN [" & fld.Name & "] TEXT(" & intFieldSize & ");"
x = x + 1
Me.lblFieldNo.Caption = "Field " & x
Me.Repaint
End If
Next
End If
Next
It errors on line CurrentDb.Execute ...
When the original table was designed, the field lengths were set to 255 and we now need to set them to 150 or perhaps a different value.
I wrote some code in a test db so that the field data lengths could be reduced. The code worked.
I transferred the code to the actual db. The code will work up to a small number of fields and then debugs to run time error 3190 i.e. too many fields. If I compact\repair the db the code then moves on further doing more fields than before and so on. Hence only by compacting\repairing the db about 20 times did I get all the fields changed.
The question is, WHY. Here's the main snippet of code: -
For Each tdf In CurrentDb.TableDefs
If tdf.Name = Me.txtTableName Then
For Each fld In tdf.Fields
If DataType(fld.Type) = "Text" Then
CurrentDb.Execute "ALTER TABLE [" & strTable & "] ALTER COLUMN [" & fld.Name & "] TEXT(" & intFieldSize & ");"
x = x + 1
Me.lblFieldNo.Caption = "Field " & x
Me.Repaint
End If
Next
End If
Next
It errors on line CurrentDb.Execute ...