1

我正在使用 MS Access 2010-2013 并且我有一个更新查询,它将一些文本替换为另一个文本。我想在我的表单上将查询转换为 VBA“Sub Removereplace ()”,以循环遍历每个有问题的文本的选择案例,并在其存在时替换它。我不知道如何做到这一点,并试图通过护目镜找到一个可行的例子,但没有运气。有任何想法吗?谢谢!!!

UPDATE tbl_ImportedTabDelimited SET tbl_ImportedTabDelimited.[Long Description] = Replace(Replace(Replace(Replace([Long Description]," ft","'")," in","""")," ""L""",""),",","")
WHERE (((tbl_ImportedTabDelimited.[Long Description]) 
Like "*ft*" Or   (tbl_ImportedTabDelimited.[Long Description]) 
Like "*in*" Or (tbl_ImportedTabDelimited.[Long   Description]) 
Like "*,*" Or (tbl_ImportedTabDelimited.[Long Description]) 
Like "*""L""*"));
4

1 回答 1

0

好的,如果您真的必须在循环中更新 VBA 中的内容:

Sub ThisIsABadIdea()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT Title, Name, Salary FROM Table1")

    rs.MoveFirst
    While Not rs.EOF
        rs.Edit

        ' Multiple field update
        If Left(rs!Title, 1) = "Z" Then
            rs!Title = "Omega Man"
            rs!Name = "Heston"
            rs!Salary = 15000
        End If

        ' Multiple condition on one field
        Select Case rs!Title
        Case rs!Title = "aa":
            rs!Title = "no way!"
        Case Left(rs!Title, 4) = "xyxy":
            rs!Title = "Double Fem!"
        Case Right(rs!Title, 2) = "-2":
            rs!Title = "It's a dash two experience"
        Case Else
            rs!Title = "It is indescribable"
        End Select

        rs.Update
        rs.MoveNext
    Wend
    rs.Close
End Sub
于 2013-02-25T05:01:54.230 回答