Link to home
Start Free TrialLog in
Avatar of leezac
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.
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Are you replacing DATA? That is, you need to update a Table?

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("YourDatabasePath")

dbs.Execute "UPDATE MyTAble blah blah"
Avatar of leezac
leezac

ASKER

It is just code  - no tables
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of leezac

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.
Avatar of leezac

ASKER

I am going to repost .  Thanks for help.
Avatar of leezac

ASKER

I reposted at

https://www.experts-exchange.com/questions/27840140/Call-Function.html

I would greatly appreciate your help.
Avatar of leezac

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
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