[AccessD] Delete all reports and all forms

Max Wanadoo max.wanadoo at gmail.com
Thu Mar 18 11:21:39 CDT 2010


AD,

There were some problems with the code so I am posting back what I ended up
with.
Once again, for me, Access did not like deleting the Forms, so I just had to
jump around the error (as shown). Also a test for zero Forms.

Any thoughts on the error?

Max

Public Function libDeleteLocalForms()
  On Error GoTo EH
  Dim obj As Object, Rtv As Variant, Cnt As Long
  If CurrentProject.AllForms.Count > 0 Then
    ReDim Rtv(CurrentProject.AllForms.Count - 1)
    Cnt = 0
    For Each obj In CurrentProject.AllForms
      DoCmd.Close acForm, obj.Name
      Rtv(Cnt) = obj.Name
      Cnt = Cnt + 1
    Next
    For Cnt = 0 To UBound(Rtv)
      DoCmd.DeleteObject acForm, Rtv(Cnt)
    Next
  End If
EX:
  Set obj = Nothing
  Exit Function
EH:
  Select Case Err.Number
  Case 29068
    Resume Next
  Case Else
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    Resume EX
  End Select
End Function
 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of A.D. Tejpal
Sent: Wednesday, March 17, 2010 6:34 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Delete all reports and all forms

Max,

    It can be done quite conveniently in DAO. For smooth deletion of all
forms/reports, you have to do the deletion part outside the For Each loop. 

    Sample procedure named P_DeleteAllForms() as given below, will remove
all forms in the db. Just make sure that all forms are in closed state
before running the subroutine.

    Similar procedure can be devised for deleting all reports.

Best wishes,
A.D. Tejpal
------------

' Sample procedure for deleting all forms.
'===========================
Sub P_DeleteAllForms()
    ' Before running this subroutine,
    ' pl. make sure that no form is in open state
    Dim obj As Object
    Dim Rtv As Variant, Cnt As Long
    
    ReDim Rtv(CurrentProject.AllForms.Count - 1)
    Cnt = 0
    For Each obj In CurrentProject.AllForms
        Rtv(Cnt) = obj.Name
        Cnt = Cnt + 1
    Next
    
    For Cnt = 0 To UBound(Rtv)
        DoCmd.DeleteObject acForm, Rtv(Cnt)
    Next
    
    Set obj = Nothing
End Sub
'===============================

  ----- Original Message -----
  From: Max Wanadoo
  To: 'Access Developers discussion and problem solving' 
  Sent: Wednesday, March 17, 2010 21:58
  Subject: [AccessD] Delete all reports and all forms


  Anybody know how to loop through and delete all reports and all forms.

  It seems that Access will not let you delete from the collections.

  Must be a programmable way but never done it before.

  Max
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list