如何使用 增加MDB
字段大小的大小DAO
?
问问题
2680 次
2 回答
3
使用 DDL 可以更轻松地做到这一点:
Set db = CurrentDb
sSQL = "ALTER TABLE table1 ALTER Column atext text(150)"
db.Execute sSQL, dbFailOnError
显然,这在 MS Access 97 中不可用,但在此后 15 年的任何版本中,我建议 DDL 是最简单的方法。
于 2012-09-12T09:25:55.817 回答
2
来自http://www.freevbcode.com/ShowCode.asp?ID=4599:
Public Sub change_field_size(DBPath as string, _
tblName As String, fldName As String, fldSize As Integer)
' this routine changes the field size
Dim db As Database
Dim td As TableDef
Dim fld As field
On Error GoTo errhandler
Set db = OpenDatabase(DBPath)
Set td = db.TableDefs(tblName)
If td.Fields(fldName).Type <> dbText Then
' wrong field type
db.Close
Exit Sub
End If
If td.Fields(fldName).size = fldSize Then
' the field width is correct
db.Close
Exit Sub
End If
' create a temp feild
td.Fields.Append td.CreateField("temp", dbText, fldSize)
td.Fields("temp").AllowZeroLength = True
td.Fields("temp").DefaultValue = """"""
' copy the info into the temp field
db.Execute "Update " & tblName & " set temp = " & fldName & " "
' delete the field
td.Fields.Delete fldName
' rename the field
td.Fields("temp").Name = fldName
db.Close
'======================================================================
Exit Sub
errhandler:
MsgBox CStr(Err.Number) & vbCrLf & Err.Description & vbCrLf & "Change Field Size Routine", vbCritical, App.Title
End Sub
于 2012-09-12T09:23:12.367 回答