|
在模块中复制下面的代码,运行之.当然你要根据你的情况处理一下.
Public Sub AddField()
'将数据库中现有的表中加上两个新的字段mm和nn,分别是文本和日期
Dim rs As DAO.Recordset
Dim sql As String
Dim tabName As String
Dim I As Integer
'生成只有一个字段的记录集,该字段保存的是库中所有表的名称
sql = "SELECT MSysObjects.Name" & _
" FROM MSysObjects" & _
" WHERE ((Left([name],4)<>'Msys') AND ((MSysObjects.Type)=1));"
Set rs = CurrentDb.OpenRecordset(sql)
rs.MoveFirst
'将每个表加上两个字段mm 和 nn
Do Until rs.EOF
tabName = rs(0)
DoCmd.RunSQL "ALTER TABLE " & rs(0) & " add mm text(9),nn date"
rs.MoveNext
Loop
Set rs = Nothing
End Sub |
|