How do you print an embeded macro? (1 Viewer)

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
I have a form that has a command button which executes a rather lengthy embeded macro. Does anyone know how to write a report so I can keep a printed copy of the macro? I DO NOT want to use the built-in Database Documentor; the report isn't formatted the way I want? I would be happy to modify the Database Documentor report if I can find a way.

Thanks!

Chuck
 
Last edited:

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
Access 2010
 

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
Do you know how to modify the "canned" Database Tools reports?

Chuck
 

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
How do third-party companies write Access documentation programs? What information/tables do they access?
 

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
Thanks Bob, I'll take a look at it. If anyone else has any ideas, I would appreciate your thoughts.

Chuck
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:13
Joined
Feb 19, 2002
Messages
43,275
Here's one procedure from my documentation database. This one loops through the fields collection of the tabledefs collection and adds each field to a table. I use the table to produce reports that are more detailed and better formatted than the built in reports.
Code:
Sub Create_tblTableFields()

    Dim db As DAO.Database
    Dim tblLoop As DAO.TableDef
    Dim fldLoop As DAO.Field
    Dim TD1 As DAO.TableDef
    Dim QD1 As DAO.QueryDef
    Dim TempSet1 As DAO.Recordset
    Dim strDatabase As String
    Dim ThisDB As DAO.Database
    Dim CountTables As Integer
    
   On Error GoTo Create_tblTableFields_Error

  On Error GoTo Err_Create_tblTableFields
    'strDatabase = "C:\hartman\LinkDB2.mdb"
    strDatabase = Forms!frmPrintDoc!txtDBName
    
    CountTables = 0
    Set ThisDB = CurrentDb()
    If strDatabase = "" Then
        Set db = CurrentDb()
    Else
        Set db = DBEngine.Workspaces(0).OpenDatabase(strDatabase)
    End If
    
    db.Containers.Refresh
    
    Set QD1 = ThisDB.QueryDefs!QdeltblTableFields
        QD1.Execute
    Set TD1 = ThisDB.TableDefs!tblTableFields
    Set TempSet1 = TD1.OpenRecordset

    ' Loop through TableDefs collection.
    For Each tblLoop In db.TableDefs
        ' Enumerate Fields collection of each
        ' TableDef object.
        CountTables = CountTables + 1
        Forms!frmPrintDoc!txtTableCount = CountTables
        Forms!frmPrintDoc!txtTableName = tblLoop.Name
        Forms!frmPrintDoc.Repaint
                
        If Left(tblLoop.Name, 4) = "MSys" Or Left(tblLoop.Name, 2) = "xx" Or Left(tblLoop.Name, 2) = "zz" Or Left(tblLoop.Name, 1) = "~" Then
        Else
            For Each fldLoop In tblLoop.Fields
                TempSet1.AddNew
                TempSet1!TableName = tblLoop.Name
                TempSet1!FieldName = fldLoop.Name
                TempSet1!OrdinalPosition = fldLoop.OrdinalPosition
                TempSet1!AllowZeroLength = fldLoop.AllowZeroLength
                TempSet1!DefaultValue = fldLoop.DefaultValue
                TempSet1!Size = fldLoop.Size
                TempSet1!Required = fldLoop.Required
                TempSet1!Type = fldLoop.Type
                TempSet1!ValidationRule = fldLoop.ValidationRule
                TempSet1!Attributes = fldLoop.Attributes
                On Error Resume Next ' the following property is only available when it is not null
                TempSet1!Description = fldLoop.Properties("Description")
                TempSet1!FieldType = GetType(fldLoop.Type)
                TempSet1!Caption = fldLoop.Properties("Caption")
                If fldLoop.Attributes And dbAutoIncrField Then  'performs bitwise operation
                    TempSet1!AutoNum = True
                    TempSet1!Required = True
                Else
                    TempSet1!AutoNum = False
                End If
                TempSet1.Update
            Next fldLoop
        End If
    Next tblLoop

Exit_Create_tblTableFields:
    db.Close
    Exit Sub

Err_Create_tblTableFields:
    Select Case Err.Number
        Case 3043
            MsgBox "Please select a valid database", vbOKOnly
        Case 91   ' db was not opened so it cannot be closed.
            Exit Sub
        Case Else
            MsgBox Err.Number & "-" & Err.Description
    End Select
    Resume Exit_Create_tblTableFields

   On Error GoTo 0
   Exit Sub

Create_tblTableFields_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Create_tblTableFields of Module DocumentCollections"
End Sub
 

chuckcoleman

Registered User.
Local time
Today, 05:13
Joined
Aug 20, 2010
Messages
363
Pat, thank you very much. I'll take a hard look at this to see if I can modify it. When you said it "loops through the fields collection of the tabledefs collection", I'm not familiar with what is stored in tabledefs. It looks like it's looks in a control on a form called frmPrintDoc. I have a form that has a command button on it and in the On Click event, it runs an embeded macro. Will your code be able to pick out the key elements of the macro and then stick them into a new table? If so, I could then write a report to extract the information I'm looking for. Does this make sense?
 

AtLarge

Registered User.
Local time
Today, 05:13
Joined
Oct 15, 2008
Messages
70
Don't know if this will help but you can export Access 2010 macros to XML.

Can you put together a brief process for this? I'd like to be able to print some of my lengthy macros too. I would settle for an .xml version depending on what it looks like. I don't see a way to do this? :banghead:
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:13
Joined
Feb 19, 2002
Messages
43,275
Pat, thank you very much. I'll take a hard look at this to see if I can modify it. When you said it "loops through the fields collection of the tabledefs collection", I'm not familiar with what is stored in tabledefs. It looks like it's looks in a control on a form called frmPrintDoc. I have a form that has a command button on it and in the On Click event, it runs an embeded macro. Will your code be able to pick out the key elements of the macro and then stick them into a new table? If so, I could then write a report to extract the information I'm looking for. Does this make sense?

The form reference is to the form that is actually running the code. I have a separate documentation database. In it I have a form that allows me to choose which database I want to document. The code then opens that database and reads through some of the collections to create the documentation I use in place of what Access supplies.

Sorry, the code doesn't look at macros. I never use macros in any of my applications. The concept would be similar but the collection name and properties would be different.
 

boblarson

Smeghead
Local time
Today, 03:13
Joined
Jan 12, 2001
Messages
32,059
Can you put together a brief process for this? I'd like to be able to print some of my lengthy macros too. I would settle for an .xml version depending on what it looks like. I don't see a way to do this? :banghead:
I do know how to do it manually (I had to double check it at home though) and that is to open them in design view and then use Ctrl+A to select it all and then Ctrl+C to copy and then you can paste it into Notepad, Word, whatever.
 

Users who are viewing this thread

Top Bottom