Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    View code from Word (2000)

    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.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: View code from Word (2000)

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

  3. #3
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View code from Word (2000)

    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).

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: View code from Word (2000)

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

  5. #5
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View code from Word (2000)

    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

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: View code from Word (2000)

    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

  7. #7
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View code from Word (2000)

    Absolutely fantastic. <img src=/S/clapping.gif border=0 alt=clapping width=19 height=23> I had DoCmd.OpenForm instead of accApp.DoCmd.OpenForm, so of course Word would not know what to do. <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> The rest should be a breeze.

    Many thanks!!!!!

  8. #8
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View code from Word (2000)

    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?

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: View code from Word (2000)

    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

  10. #10
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: View code from Word (2000)

    Looks promising. Thanks!

Posting Permissions

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