I want to make a VBA script that goes through the directories, opens my database access and will modify a certain character string with another in the modules and Forms code.
I can browse my folders and open my databases, but I don't know how to modify the code.
For now I have this code which allows me to find the character string but not to replace it. :
Dim msACC As Access.Application
Set msACC = GetObject(file.Path)
For i = 0 To msACC.Modules.Count - 1
If (msACC.Modules.Item(i).Find(TextToFind, 0, 0, 100000, 100000)) Then
'Find it
End If
Next i
msACC.Quit
Set msACC = Nothing
I find this solution that works for me :
Set re = New RegExp
re.Pattern = TextToFind
Dim msACC As Access.Application
Set msACC = GetObject(file.Path)
For i = 0 To msACC.Modules.Count - 1
With msACC.Modules.Item(i)
For j = 1 To .CountOfLines
If InStr(.Lines(j, 1), TextToFind) > 0 Then
.ReplaceLine j, re.Replace(msACC.Modules.Item(i).Lines(j, 1), TextToReplace)
End If
Next j
End With
Next i
msACC.Quit
Set msACC = Nothing