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

    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.

    Code:
    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 offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,695
    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
    Posts
    228
    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
    Location
    Ontario, Canada
    Posts
    8,790
    A form has a module property that you should be able to work with.
    Check these out https://msdn.microsoft.com/en-us/library/office/ff836688.aspx
    http://stackoverflow.com/questions/8...cess-using-vba
    - "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