Lost VBA code - how to import? (1 Viewer)

Yuly17

New member
Local time
Today, 01:55
Joined
Nov 10, 2022
Messages
14
Hi, i have a failure in my computer and all vba code is lost in my access file and back up. All the new tables and forms are there.

I have an older back up file but i don't know how to pull the full code from one file to the other?

Can someone explain to me how to do it? I did try to export each component individually but when trying to import to the file (with the missing code) it gives me an error the module.name form_api is invalid.

Not sure what else to do.

Thanks in advance
 
You should be able to import standard and class modules, but form class modules probably require that you import the form or report objects instead.
 
docmd.transferspreadsheet...
or
docmd.transfertext....
 
The Access.Application object exposes two hidden methods you might use in this case, SaveAsText() and LoadFromText(). Using SaveAsText() you can save the complete definition of any Query, Form, Report, Macro, or Module. Using LoadFromText() you can then load any saved definition back into an Access.Application object.

Here's a simple loop that copies access objects from an application called src, to an application called dst...
Code:
Sub CopyAccessObjects(SrcAllItems As Object, ObjectType As AcObjectType)
    Dim tmp As AccessObject
    Dim spec As String
    
    spec = CurrentProject.Path & "\accobj1.txt"
    
    For Each tmp In SrcAllItems
        Me.src.SaveAsText ObjectType, tmp.Name, spec
        Me.dst.LoadFromText ObjectType, tmp.Name, spec
    Next
End Sub
 
if it is lost, then it is lost forever.
adding more Code to it will just Overwrite your old code.
 
Hi Yuly17, we use this tools for export entire Access project on text files
Basically every form, report, query, macro is exported as a single text file
For forms the initial part (of the text file) describes the user interface and the final part contains the code of the individual sub/functions
You could test this on the actual corrupted file, and try replacing the tail of each file describing a form with the code you have from the backup files And then try rebuilding the project by doing the reverse operation, and then rebuilding the project
 

Users who are viewing this thread

Back
Top Bottom