leezac
asked on
Code to search for filename and replace
I need a way to search for //ABCD and replace with ABC1 in multiple databases? Is there a way to use one database to open other databases? Or just insert code into each database to do the search. I am need a quick way for many databases to do and find and replace.
ASKER
It is just code - no tables
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
LSM Consulting - sorry I had been out and did not see your reply until today. Does the code above search modules only? If so, do I need to know the modules name? I do not want to open each database, but scan for any VBA to find a certain string. Thank you.
ASKER
I am going to repost . Thanks for help.
ASKER
I reposted at
https://www.experts-exchange.com/questions/27840140/Call-Function.html
I would greatly appreciate your help.
https://www.experts-exchange.com/questions/27840140/Call-Function.html
I would greatly appreciate your help.
ASKER
LSM - I am really having trouble trying to figure out how to call the function to make it work.....
Can you help please?
Public Function searchorreplace(ByVal Module As Access.Module, ByVal StringToFind As String, _
Optional ByVal NewString, Optional ByVal FindWholeWord = False, _
Optional ByVal MatchCase = False, Optional ByVal PatternSearch = False) As Boolean
Set mdl = Module
'Now call the SearchOrReplace function like this:
Dim oAcc As Access.Application
Set oAcc = New Access.Application
oAcc = OpenCurrentDatabase("P:/")
Dim mdl As Access.Module
For Each mdl In oAcc.Modules
searchorreplace mdl, "Dim" '"NewString"
Next
Dim oAcc As Access.Application
oAcc.Modules
Can you help please?
Public Function searchorreplace(ByVal Module As Access.Module, ByVal StringToFind As String, _
Optional ByVal NewString, Optional ByVal FindWholeWord = False, _
Optional ByVal MatchCase = False, Optional ByVal PatternSearch = False) As Boolean
Set mdl = Module
'Now call the SearchOrReplace function like this:
Dim oAcc As Access.Application
Set oAcc = New Access.Application
oAcc = OpenCurrentDatabase("P:/")
Dim mdl As Access.Module
For Each mdl In oAcc.Modules
searchorreplace mdl, "Dim" '"NewString"
Next
Dim oAcc As Access.Application
oAcc.Modules
Add the SearchOrReplace code to a standard Module (name the module something like basSearch).
In another function, do this:
Function ChangeCode As Boolean
Dim oAcc As Access.Application
Set oAcc = New Access.Application
oAcc = OpenCurrentDatabase("Full path to your external db")
Dim mdl as Access.Module
For each mdl in oAcc.Modules
SearchOrReplace mdl, "StingToFine", "NewString" etc etc
Next
Set oAcc = Nothing
End Function
In another function, do this:
Function ChangeCode As Boolean
Dim oAcc As Access.Application
Set oAcc = New Access.Application
oAcc = OpenCurrentDatabase("Full path to your external db")
Dim mdl as Access.Module
For each mdl in oAcc.Modules
SearchOrReplace mdl, "StingToFine", "NewString" etc etc
Next
Set oAcc = Nothing
End Function
Or are you trying to find this in Code?
If it's just Data, you can simply connect to the database and update as needed:
Dim dbs As DAO.Database
dbs = OpenCurrentDatabase("YourD
dbs.Execute "UPDATE MyTAble blah blah"