Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Location
    Athens
    Posts
    3

    Unanswered: Export all code of mdb to txt file

    Is it possible to export all the code of an mdb (forms, queries, modules, etc) into one large txt file?

    C.

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    I've never tried to put all the code into one text file, but you can use the SaveAsText command to export a module into a text file. If you can't put them all into one, then you can probably use fso to get them into one.
    Me.Geek = True

  3. #3
    Join Date
    Jul 2009
    Location
    Athens
    Posts
    3
    Well I already know that part of individual modules.
    What I was wondering is if there is a way to get everything out on a txt file.

    C.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Yes you can. SaveAsText works for any kind of object in an Access database.

    Have a nice day!

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    The answer you may need is simply this: Not without coding.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    May 2005
    Posts
    1,191
    Quote Originally Posted by StarTrekker
    The answer you may need is simply this: Not without coding.
    Well, you could always copy-paste everything into a text file, that doesn't require coding
    Me.Geek = True

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Very true. I've done that before too... waste of time as it was.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    It should be something like this:
    Code:
    Public Function ExportdatabaseObjects(Optional Database As String, Optional Path As String)
    '
    ' Export all objects in a database.
    '
        Dim dbs As Database
        Dim rst As DAO.Recordset
        Dim rstFilter As DAO.Recordset
        Dim strFilter As String
        Dim strSQL As String
        Dim strName As String
        Dim strObject As String
        Dim lngType As Long
        Dim i As Integer
        
        If Database = "" Then Database = CurrentProject.Name
        If Path = "" Then Path = Replace(CurrentDb.Name, Database, "")
        If Right(Path, 1) <> "\" Then Path = Path & "\"
        Set dbs = Application.DBEngine.Workspaces(0).OpenDatabase(Path & Database)
        strSQL = "SELECT Name, Type FROM MSysObjects WHERE Flags >= 0 AND Name NOT LIKE '~*' AND Name NOT LIKE 'MSys*'"
        Set rst = dbs.OpenRecordset(strSQL, dbOpenSnapshot)
        With rst
            For i = 1 To 7
                strObject = Choose(i, "Table", "Query", "Form", "Report", "Page", "Macro", "Module")
                strFilter = "Type IN ( " & Choose(i, "1, 4, 6", "5", "-32768", "-32764", "-32756", "-32766", "-32761") & " )"
                .Filter = strFilter
                Set rstFilter = rst.OpenRecordset
                With rstFilter
                    Do Until .EOF
                        strName = !Name
                        lngType = Choose(i, acDiagram, acQuery, acForm, acReport, acPage, acMacro, acModule)
                        Application.SaveAsText lngType, strName, Path & strObject & "_" & strName & ".txt"
                    .MoveNext
                    Loop
                    .Close
                End With
            Next i
            .Close
        End With
        Set dbs = Nothing
        Set rst = Nothing
        Set rstFilter = Nothing
    
    End Function
    Have a nice day!

Posting Permissions

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