1
我需要你的幫助。我想改變一個字符而不是所有的數據庫,我有幾個表和字段。所以我在VB中構建一個函數,但這並沒有改變,我也沒有錯誤。我認爲我的條件是假的,但我沒有看到如何糾正它:/更改所有文本字段中的字符
Public Sub updateField()
Dim db As DAO.Database, td As DAO.TableDef, field As DAO.field
Dim rs As DAO.Recordset, sSQL As String, sData As String
Set db = CurrentDb
Change = "\"""
replaced = """"
'each table in db
For Each tbd In db.TableDefs
'each field in table
For Each fld In tbd.Fields
'check if String Data have my character
If InStr(1, fld.Name, Change) Then
sSQL = "UPDATE " & tbd.Name & " SET " & fld.Name & " = replace([" & fld.Name & "], " & Change & ", " & replaced & ")"
db.Execute sSQL
End If
Next
Next
End Sub
編輯: 我終於發現了什麼問題。如果有人有興趣:
Set db = CurrentDb
Change = "\"""
replaced = """"
'each table in db
For Each tbd In db.TableDefs
'each field in table
For Each fld In tbd.Fields
If Left(tbd.Name, 4) <> "MSys" And Left(tbd.Name, 4) <> "~TMP" Then
If fld.Type = dbText Or fld.Type = dbMemo Then
sSQL = "UPDATE " & tbd.Name & " SET " & fld.Name & " = replace([" & fld.Name & "],'" & Chr(92) + Chr(34) & "','" & Chr(34) & "')"
db.Execute sSQL
'Debug.Print (sSQL)
End If
End If
Next
Next
THX對您有所幫助球員;)
伊克,舊的DAO對象。我感覺骯髒只是讀這個。 –
所以你想改變數據庫中的字段名稱?或存儲在這些字段中的數據值?你的邏輯似乎試圖取代字段名稱,而不是值。 – xQbert
是的,我試圖改變字段^^的值,但我不知道如何做到這一點:/ Thx – user2822320