|
Public Sub Capitalization()
Dim db As DAO.Database
Dim rsdb As DAO.Recordset
Dim rs As DAO.Recordset
Dim sql As String
Dim qd As DAO.QueryDef
Dim i As Integer
Dim upfield As String
sql = "SELECT MSysObjects.Name, MSysObjects.Type" & _
" FROM MSysObjects" & _
" WHERE ((Mid([Name], 1, 4) <> 'Msys') And ((MSysObjects.Type) = 1))"
Set rsdb = CurrentDb.OpenRecordset(sql)
Set qd = CurrentDb.QueryDefs("查询1")
Do Until rsdb.EOF
Set rs = CurrentDb.OpenRecordset(rsdb(0))
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).Type = dbText Or rs.Fields(i).Type = dbMemo Then
upfield = upfield & rs.Fields(i).Name & "=ucase([" & rs.Fields(i).Name & "]),"
End If
Next
If upfield <> "" Then
qd.sql = "update [" & rsdb(0) & "] set " & Mid(upfield, 1, Len(upfield) - 1)
qd.Close
CurrentDb.Execute "查询1"
upfield = ""
End If
rsdb.Move 1
Loop
Set rsdb = Nothing
Set rs = Nothing
Set qd = Nothing
End Sub
用法,随便建立一个查询,命名为“查询1"
然后运行上面的代码。
上面的代码只对文本字段和备注字段有效。 |
|