|
原帖由 fang123 于 2008-3-28 17:17 发表
谢谢kangking,提一个太过份的请求:能不能帮我用一个实例演示一下,非常谢谢!
Public Sub fitSize()
Dim a()
Dim i As Integer
Dim j As Integer
Dim rs As DAO.Recordset
Dim db As DAO.Database
Set db = CurrentDb
Set rs = db.OpenRecordset("w1")
j = rs.Fields.Count
ReDim a(j, 2)
For i = 0 To j - 1
a(i, 1) = rs.Fields(i).Name
a(i, 2) = DMax("len(trim(" & rs.Fields(i).Name & "))", "w1")
Next
rs.Close
Set rs = Nothing
For i = 1 To j - 1
db.Execute "alter table w1 alter column " & a(i, 1) & " char(" & a(i, 2) & ")"
Next
End Sub |
|