Results 1 to 4 of 4
  1. #1
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012

    Replacing String Within Form Module

    At my work we changed out network mapping, and therefore there is a lot of chaos regarding directory links. I'm looking for an easy way to programmatically replace string in ALL modules within a database.

    I've found how to do it in regular modules, however I do not know how to do the same for Form Modules, or Report Modules, etc.

    Function modulechanges(Optional oldstring As String = "", Optional newstring As String = "")
    For Each mdl In CurrentProject.AllModules
        With mdl
            If mdl.Name <> "Directory Change" Then
                DoCmd.OpenModule mdl.Name
                With Application.Modules(mdl.Name)
                    For i = 1 To .CountOfLines
                        If InStr(1, .Lines(i, 1), oldstring) <> 0 Then
                                .ReplaceLine i, Replace(.Lines(i, 1), oldstring, newstring)
                        End If
                    Next i
                End With
                DoCmd.Save acModule, mdl.Name
            End If
        End With
    Next mdl
    End Function
    Is it possible to do the same for Form/report modules?

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Search/Replace is a standard option in VBE. It will work across the entire project. Check out the binoculars icon.

  3. #3
    kdbailey is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Aug 2012
    I know ctrl-H works wonders, but I do not want to do it for everybody, instead let the macro do the work.

  4. #4
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Ontario, Canada
    A form has a module property that you should be able to work with.
    Check these out
    - "doesn't work" doesn't help. Implement changes in copies of your database.
    Iím telling everyone it's good to eat dried grapes. Itís all about raisin awareness.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-12-2015, 12:03 AM
  2. Replies: 6
    Last Post: 10-17-2014, 09:38 AM
  3. Replies: 4
    Last Post: 08-14-2012, 07:14 AM
  4. class module vs regular module
    By Madmax in forum Modules
    Replies: 1
    Last Post: 05-01-2012, 03:44 PM
  5. Replies: 4
    Last Post: 05-16-2011, 04:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Other Forums: Microsoft Office Forums - Senior Forums