• View code from Word (2000)

    Author
    Topic
    #434898

    How do you go about accessing the code behind forms and modules from Word? From Access, you can do a DoCmd OpenForm, followed by a Application.Modules(n).Lines.

    From Word I create an Access object and a Forms object, but then how do I access the lines of code from there? The DoCmd Open Form will not work from Word.

    Thanks.

    Viewing 1 reply thread
    Author
    Replies
    • #1026444

      What exactly do you want? Do you want to manipulate Word code from Word, or Access code from Word, or Word code from Access?

    • #1026445

      I simply want to be able to extract into a report what code is behind the modules and forms in an Access database. I want to be able to do it from Word. (From Access is easy).

      • #1026448

        Why don’t you create a report in Access and export it to RTF format?

        • #1026453

          I already am able to do that from Access (it’s kind of neat watching hundreds of forms and modules open and close while the code is being extracted). That involves touching the database and modifying it. I want to be able to just get the info from the database without actually having to do anything to the database.

          Thanks

          • #1026457

            Here is some code you can use as a starting point. It processes forms only. Reports and modules are similar. I’ll leave it to you to add bells and whistles. You need a reference to the Microsoft Access 9.0 Object library in Word.

            Sub ListCode()
            Dim accApp As New Access.Application
            Dim accObj As Access.AccessObject
            Dim accFrm As Access.Form
            Dim accMdl As Access.Module

            On Error GoTo ErrHandler

            ‘ Substitute path and filename of database
            accApp.OpenCurrentDatabase “Test.mdb”
            For Each accObj In accApp.CurrentProject.AllForms
            accApp.DoCmd.OpenForm accObj.Name, acDesign
            Set accFrm = accApp.Forms(accObj.Name)
            If accFrm.HasModule Then
            Selection.TypeText accObj.Name & vbCr & vbCr
            Set accMdl = accFrm.Module
            Selection.TypeText accMdl.Lines(1, accMdl.CountOfLines)
            Selection.TypeText vbCr & vbCr
            End If
            accApp.DoCmd.Close acForm, accObj.Name, acSaveNo
            Next accObj

            ExitHandler:
            On Error Resume Next
            accApp.CloseCurrentDatabase
            accApp.Quit
            Set accMdl = Nothing
            Set accFrm = Nothing
            Set accObj = Nothing
            Set accApp = Nothing
            Exit Sub

            ErrHandler:
            MsgBox Err.Description, vbExclamation
            Resume ExitHandler
            End Sub

            • #1026464

              Absolutely fantastic. clapping I had DoCmd.OpenForm instead of accApp.DoCmd.OpenForm, so of course Word would not know what to do. stupidme The rest should be a breeze.

              Many thanks!!!!!

            • #1026608

              As a follow on annoyance, when the code is extracted from the forms and reports, the form or report briefly flashes on the screen when it is opened and that slows things down. No problem there, just make the app non-visible. With the modules, however, making the app non-visible doesn’t work since it is the VB window that is opened. How do I keep the VB window non-visible for the Access apps being opened?

            • #1026610

              I haven’t tested it in Access, but try the code from the Eliminating Screen Flickering section of Chip Pearson’s Programming To The VBE. You’d use accApp (or whatever your Access.Application object is named) instead of Application

            • #1026621

              Looks promising. Thanks!

    Viewing 1 reply thread
    Reply To: View code from Word (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: