Consulting

Results 1 to 2 of 2

Thread: Find and replace on all forms, Not enough Memory

  1. #1
    VBAX Mentor Movian's Avatar
    Joined
    Aug 2008
    Location
    NC, USA
    Posts
    399

    Find and replace on all forms, Not enough Memory

    Hey,

    so I find the need to change the Open_form event on all forms in the system from Private to Public (at least I need to do this for 75% of forms)

    so rather than go through each of our forms (a couple hundred) I thought I could just do a nice find and replace

    Find
    Private Sub Form_Open(Cancel As Integer)
    Replace with
    Public Sub Form_Open(Cancel As Integer)

    Set to entire project and then replace all.


    The problem is access appears to start this process then complains it doesn't have enough memory to complete the task and crashes. (Access 2010)

    I don't believe the DB is corrupted and it is entirely possible that as a 32 bit application it doesn't have enough memory for this...

    I tried setting the large address aware flag for the executable this removed the warning message but access still crashed at the same point.....

    Any suggestions for this? Perhaps I could export all the forms as text and then do some kind of batch process then import them all?

    Anyone else run into this issue?

    Thanks in advance!
    "From the ashes of disaster grow the roses of success" - Chitty chitty bang bang

    "I fear not the man who has 10,000 kicks practiced once. I fear the man who has 1 kick practiced 10,000 times" - Bruce Lee

  2. #2
    VBAX Mentor Movian's Avatar
    Joined
    Aug 2008
    Location
    NC, USA
    Posts
    399
    So,

    found a process to sort this out,

    1) Export all forms to text files
    2) Use Notepad++ to find and replace text in all text files
    3) Delete all forms
    4) Import all forms from text files

    Wrote some subs for this if others needs this in future,

    One issue is that the delete forms sub needs to be run several times as it runs into an unknown error (Presuming that the deleting of the forms is causing an array problem in the for next loop) however running several times until all forms deleted does work.

    Option Compare DatabaseOption Explicit
    
    
    Sub ExportAllFormsToText()
    Dim MyForm As Object
    Dim Location As String
    Dim FileExtension As String
    
    
    Location = "D:\Work\SonoSoft\Form Text Export\"
    FileExtension = ".txt"
    
    
    For Each MyForm In CurrentProject.AllForms
        Application.SaveAsText acForm, MyForm.Name, Location & MyForm.Name & FileExtension
    Next
    MsgBox "Complete"
    End Sub
    
    
    Sub DeleteAllForms()
    If MsgBox("Are you sure you want to delete all forms?", vbYesNo) = vbNo Then
        Exit Sub
    End If
    
    
    Dim MyForm As Object
    Dim varReturn As Variant
    For Each MyForm In CurrentProject.AllForms
        varReturn = SysCmd(acSysCmdSetStatus, MyForm.Name)
        DoCmd.DeleteObject acForm, MyForm.Name
        DoEvents
    Next
    
    
    MsgBox "Complete"
    End Sub
    
    
    Sub ImportAllFormsFromText()
    If MsgBox("Are you sure you wish to import all form text files?", vbYesNo) = vbNo Then
        Exit Sub
    End If
    Dim Location As String
    Dim FileExtension As String
    Dim myfile As String
    Dim varReturn As Variant
    
    
    Location = "D:\Work\SonoSoft\Form Text Export\"
    FileExtension = ".txt"
    
    
    myfile = Dir(Location & "\" & FileExtension)
    
    
    Do While myfile <> ""
        varReturn = SysCmd(acSysCmdSetStatus, myfile)
        Application.LoadFromText acForm, left(myfile, Len(myfile) - 4), Location & "\" & myfile
        myfile = Dir
        DoEvents
    Loop
    MsgBox "Complete"
    End Sub
    "From the ashes of disaster grow the roses of success" - Chitty chitty bang bang

    "I fear not the man who has 10,000 kicks practiced once. I fear the man who has 1 kick practiced 10,000 times" - Bruce Lee

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •