Access 2.0 - DeleteObject A_MODULE


Question

DoCmd DeleteObject A_MODULE, "ModuleName" does not work in VB for v2.0. Does anyone know a workaround. (Someone asked the exact same question about 3 years ago with no response.)

Answer

From: Shamil Salakhetdinov <shamil@marta.darts.spb.ru>
To: ACCESS-L <ACCESS-L@PEACH.EASE.LSOFT.COM>
Subject: Re: v2.0 - DeleteObject A_MODULE
Date: 16 июля 1998 г. 1:23

Enclosed you find the functions I wrote about three years ago. I used them in my MS Access 2.0 Builds Coordination Utility, I found that to be able to delete modules you have to write some code and three macros:

  1. main macro used to :
    • fill in the table with objects' names and types to delete and DelMe flag
    • set repeat count for the second macro
    • issue "delete in progress..." message
    • call second macro
    • clear "delete in progress..." message
  2. delete object shell used to repeatedly call third macro;
    • runcode crChangeObjectToDelete
    • runmacro ~crmcrDeleteObjectInCrMdb

As far as I can remember you can delete modules in MS Access 2.0 if and only if you do this using macro as entry (starting) point, i.e. you cannot runmacro from module to delete another modules but you can runmacro (cycled) which uses functions used to prepare macros to delete modules... ;-) Probably I missed something and there is a simpler way but this tricky solution worked OK.

HTH,
Shamil

P.S. The code:

Function crSetRepeatCount ()
  On Error GoTo crSetRepeatCount_Err
  Dim db As Database, rec As Recordset
  Dim intObjectType As Integer, strObjectName As String
  
  Set db = dbengine(0)(0)
  Set rec = db.OpenRecordset("MSYSMacros", DB_OPEN_DYNASET)
  If Not rec.eof Then
   rec.FindFirst "[Scriptname] = """ & "~crmcrFindAndDeleteObjectShell" & """"
   If Not rec.nomatch Then
    rec.MoveNext
    rec.Edit
     rec![Argument2] = crQtyOfObjectsToDelete()
    rec.Update
   End If
  End If
  
  crSetRepeatCount = True
crSetRepeatCount_Done:
  Exit Function
crSetRepeatCount_Err:
  crShowStopErrMsg "crSetRepeatCount"
  Resume crSetRepeatCount_Done


End Function

Function crChangeObjectToDelete ()
  On Error GoTo crChangeObjectToDelete_Err
  Dim db As Database, rec As Recordset
  Dim intObjectType As Integer, strObjectName As String
  
  Set db = dbengine(0)(0)
  Set rec = db.OpenRecordset("MSYSMacros", DB_OPEN_DYNASET)
  If Not rec.eof Then
   rec.FindFirst "[Scriptname] = """ & "~crmcrDeleteObjectInCrMdb" & """"
   If Not rec.nomatch Then
    rec.MoveNext
    rec.Edit
     crNextObjectToDeleteFromCrMdb intObjectType, strObjectName
     rec![Argument1] = intObjectType
     rec![Argument2] = strObjectName
    rec.Update
   End If
  End If
  
  crChangeObjectToDelete = True
crChangeObjectToDelete_Done:
  Exit Function
crChangeObjectToDelete_Err:
  crShowStopErrMsg "crChangeObjectToDelete"
  Resume crChangeObjectToDelete_Done

End Function

Sub crNextObjectToDeleteFromCrMdb (intObjectType As Integer, strObjectName As String)
   Dim dbCurr As Database, rec As Recordset, strrecSql As String
   Set dbCurr = dbengine(0)(0)
   Set rec = dbCurr.OpenRecordset("~crqselNextObjectToDelete", DB_OPEN_DYNASET)
   If Not rec.eof Then
      rec.MoveFirst
      intObjectType = rec!ObjectType
      strObjectName = rec![Name]
      rec.Edit
       rec!DeleteMeFromCrMdb = False
      rec.Update
   End If

End Sub

HOME    TOPICS

Copyright © 1995–1999 by Shamil Salakhetdinov.
All rights reserved. Terms of use.

Last updated: October 10, 2006