Help with VB code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello..
I am using the following code to delete the forms in my demo upon expiration:

Dim i As Integer
Dim strForm As String

For i = (CurrentProject.AllForms.Count - 1) To 0 Step -1
strForm = CurrentProject.AllForms(n).Name
If strForm <> Me.Name Then
DoCmd.DeleteObject acForm, strForm
End If
Next i

The code works when I place it in the on-close event of the form, however,
it does not work when placed in a module? What am I missing?
 
Because VBA recognizes what Me.Name is when you run it n the close event of
your form, but does NOT know what Me.Name is. Try changing it this way:

If strForm <> "YourFormName" Then
DoCmd.DeleteObject acForm, strForm
End If
 
Hi Lynn.. me again. I am running into the following wrinkle: During the
deletion of the forms, I get an error message 'You can't delete database
object "MyFormName" while it's open' (this would be the form that I have
coded to exclude from deletion). When I re-open the database to check, about
half of the forms remain to be deleted. By the way, the form in question is
the startup form. Additionally, I have tried not excluding any forms from
deletion, but I get the same error. Apparently when the deleting process
hits that form, the deleting stops. Have you any ideas what I might try?
 
Hi EdS,
I just ran the code without any problems. Have you stepped through your code
to see what might be happening?
 
I'm progressing as self-taught, so I will have to figure out how to do that.
Since I am about to leave for the day, I will take this up again on Monday.
I do appreciate your responses.
 
Back
Top