Delete ALL forms?

Rusty

Registered User.
Local time
Today, 11:56
Joined
Apr 15, 2004
Messages
207
Hey Guys,

I'll keep this simple and not go into too much detail (suffice it to say that I need to look into this as a function for one of our systems here).

But...is there any way of getting VBA to delete all the forms in a database?

Is it using DoCmd.DeleteObject or is this a non-flyer?

Cheers,

Rusty
:D
 
yes,
i guess its
DoCmd.DeleteObject acForm, formname

Formname can be an array with all the forms names. Then you loop it. It might exist an easier way, but that is all i know
 
Last edited:
Code:
Public Function DeleteAllForms() As Boolean

    On Error GoTo Err_DeleteAllForms

    
    Const strSQL As String = "SELECT Name " & _
                             "FROM MSysObjects " & _
                             "WHERE Type = -32768;"
                             
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    
    Set cn = CurrentProject.Connection
    Set rs = New ADODB.Recordset
    
    rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly
    
    Do While Not rs.EOF
        DoCmd.DeleteObject acForm, rs.Fields(0).Value
        rs.MoveNext
    Loop
    
    rs.Close
    cn.Close
    
    DeleteAllForms = True
    
Exit_DeleteAllForms:
    Set rs = Nothing
    Set cn = Nothing
    Exit Function
    
Err_DeleteAllForms:
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_DeleteAllForms


End Function ' DeleteAllForms
 
why would you really want to delete all forms?

do you want to split the databases between code and data - you can do it manually, but you can just the database splitter to do it for you.
 

Users who are viewing this thread

Back
Top Bottom