[AccessD] Deleting an Entire Module Procedure via code

MartyConnelly martyconnelly at shaw.ca
Tue Mar 18 03:04:01 CST 2003


StaRKeY wrote:

>Hi JB,
>
>Declare a var as module and see all the methods you can use to get your work
>done... you can use the modvar.find method probably if you already know the
>procedure name and use the proccountoflines or something to loop through all
>lines and use the deleteline method from module... what it comes down to is
>looping through the proclines and delete them....
>
>I have to say it's a bit too much work to have it laid out to you for now
>but it's almost midnight and I'm going to bed;-) Maybe another member as
>some ready-made code for you..
>
>Good luck,
>Eric
>
>-----Original Message-----
>From: accessd-admin at databaseadvisors.com
>[mailto:accessd-admin at databaseadvisors.com]On Behalf Of John Bartow
>Sent: maandag 17 maart 2003 22:46
>To: AccessD
>Subject: [AccessD] Deleting an Entire Module Procedure via code
>
>
>Anyone have advice on deleting an entire module procedure via code?
>
>JB
>
>  
>
 Here is a starting point . I just was trying to list subroutines maybe 
you can take from there.
You can also do it for forms.

Public Sub DocDatabase()
'====================================================================
' Name: DocDatabase
'
'====================================================================
On Error GoTo Err_DocDatabase
Dim dbs As Database
Dim cnt As Container
Dim doc As Document
Dim intCount As Integer
 
Set dbs = CurrentDb()        ' use CurrentDb() to refresh Collections
 
Set cnt = dbs.Containers("Modules")
    For Each doc In cnt.Documents
    Debug.Print doc.Name
    ListAllProcsOrig (doc.Name)
Next doc
 
Set doc = Nothing
Set cnt = Nothing
Set dbs = Nothing
Err_DocDatabase:
 MsgBox Err.Number & "-" & Err.Description
 GoTo Exit_DocDatabase
 
Exit_DocDatabase:
End Sub
Function ListAllProcsinForms(strModuleName As String)
'Purpose: lists all procedures/functions for given module
'Example: ListAllProcsinForms ("MyForm")
    Dim mdlF As Form
    Dim mdl As Module
    Dim lngCount As Long, lngCountDecl As Long, lngI As Long
    Dim strProcName As String, astrProcNames() As String
    Dim intI As Integer, strMsg As String
    Dim lngR As Long

    ' Open specified Module object.
    DoCmd.OpenForm strModuleName
    ' Return reference to Form object.
     
    Set mdlF = Forms(strModuleName)
    ' Return reference to Module object.
      Set mdl = mdlF.Module
    ' Count lines in module.
 
    lngCount = mdl.CountOfLines
    ' Count lines in Declaration section in module.

    lngCountDecl = mdl.CountOfDeclarationLines
    ' Determine name of first procedure.
    strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
    ' Initialize counter variable.
    intI = 0
    ' Redimension array.
    ReDim Preserve astrProcNames(intI)
    ' Store name of first procedure in array.
    astrProcNames(intI) = strProcName

    ' Determine procedure name for each line after declarations.
    For lngI = lngCountDecl + 1 To lngCount
        ' Compare procedure name with ProcOfLine property value.

        If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
            ' Increment counter.
            intI = intI + 1
            strProcName = mdl.ProcOfLine(lngI, lngR)
            ReDim Preserve astrProcNames(intI)
            ' Assign unique procedure names to array.
            astrProcNames(intI) = strProcName
        End If
    Next lngI

    strMsg = "Procedures in module '" & strModuleName & "': " _
        & vbCrLf & vbCrLf
    Debug.Print "Procedures in module '" & strModuleName & "': "

    For intI = 0 To UBound(astrProcNames)
        strMsg = strMsg & astrProcNames(intI) & vbCrLf
'Print list in debug window:
        Debug.Print astrProcNames(intI)
    Next intI

' Dialog box listing all procedures in module.
    MsgBox strMsg
End Function

Function ListAllProcsOrig(strModuleName As String)
'Purpose: lists all procs subroutine/functions for given module
'Example: ListAllProcs("MyModule")
Dim mdl As Module
Dim lngCount As Long, lngCountDecl As Long, lngI As Long
Dim strProcName As String, astrProcNames() As String
Dim intI As Integer, strMsg As String
Dim lngR As Long

' Open specified Module object.
DoCmd.OpenModule strModuleName
' Return reference to Module object.
Set mdl = Modules(strModuleName)
' Count lines in module.
lngCount = mdl.CountOfLines
' Count lines in Declaration section in module.

lngCountDecl = mdl.CountOfDeclarationLines
' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1, lngR)
' Initialize counter variable.
intI = 0
' Redimension array.
ReDim Preserve astrProcNames(intI)
' Store name of first procedure in array.
astrProcNames(intI) = strProcName

' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1 To lngCount
' Compare procedure name with ProcOfLine property value.

If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
' Increment counter.
intI = intI + 1
strProcName = mdl.ProcOfLine(lngI, lngR)
ReDim Preserve astrProcNames(intI)
' Assign unique procedure names to array.
astrProcNames(intI) = strProcName
End If
Next lngI

strMsg = "Procedures in module '" & strModuleName & "': " _
& vbCrLf & vbCrLf
Debug.Print "Procedures in module '" & strModuleName & "': "

For intI = 0 To UBound(astrProcNames)
strMsg = strMsg & astrProcNames(intI) & vbCrLf
'Print list in debug window:
Debug.Print astrProcNames(intI)
Next intI

' Dialog box listing all procedures in module.
MsgBox strMsg
End Function





More information about the AccessD mailing list