DoCmd.Close and DoCmd.DeleteObject

  • Thread starter Daniel Magnus Bennét Björck
  • Start date
D

Daniel Magnus Bennét Björck

Hi!

I have an upgrade form which replaces forms in the current database with new
versions from another database. However, when I try to delete an old form
using DoCmd.DeleteObject, I get an error message saying that the form is
still open; even though I've used DoCmd.Close on it, and it does indeed fire
and complete the Close event on that form, and it doesn't show on the screen
anymore, and an IsFormLoaded function I've picked up somewhere does also say
that it is indeed closed.

As long as the form hasn't been previously opened, it works fine. Is there
something I'm missing about closing forms? For instance, two forms I'm
particularly having problems with are using Timer events, could it be that
they are still running in some form even though the form is closed?? Or
could there be some problem with DeleteObject, in which case, is there
another way of deleting forms I could try??

Brgds

Danny
 
T

TC

You're sure that the upgrade form is not accidentally trying to delete
itself? (hence the message)

If not, perhaps compact the database & try again.

HTH,
TC
 
D

Daniel Magnus Bennét Björck

Hi!

Yes, it is trying to delete other forms, not itself. Compacting/repairing
does not help.

Brgds

Danny
 
M

MacDermott

I've run into this issue myself -
sorry that I'm not bringing up the details of the theory just now.
(It was some time ago.)
What I do recall is that you have to open another instance of Access under
Automation.
You can then do your DeleteObject there.

Please post back if you need a code sample; I'm sure I can dig one up within
a few days...

- Turtle
 
T

TC

If you're positive that the form in question is closed, and not running a
timer event, and you still can't delete it, the only other thing that I can
think of, is that the database is corrupt. Try importing all the objects
into a new db, & see if that fixes it.

You said originally: "As long as the form hasn't been previously opened, it
[the delete] works fine". Is that still true (after importing into a new
db)?

HTH,
TC
 
D

Daniel Magnus Bennét Björck

Hi!

That was a very good idea, and I've tried it out myself. However I keep
getting "The DeleteObject action was cancelled". Would you mind please
sending a code sample?

Brgds

Danny
 
D

Daniel Magnus Bennét Björck

Hi!

Recreating the database does not make a difference unfortunately. It is
still consistently not deleting forms that were previously opened, but has
no problems with the ones that weren't open. Could it be that as the form to
be deleted was open when the second form was opened, the second form still
somehow thinks it's open even though it has closed it? Perhaps there is some
system command to run after DoCmd.Close to ensure that the second form sees
that the first form really was closed?

I put in a snippet in the timer event to record when it was firing, and it
is not firing after the form has been closed. And interestingly, if I choose
End from the debug mode, I have no problems deleting the form manually!

Brgds

Danny

TC said:
If you're positive that the form in question is closed, and not running a
timer event, and you still can't delete it, the only other thing that I can
think of, is that the database is corrupt. Try importing all the objects
into a new db, & see if that fixes it.

You said originally: "As long as the form hasn't been previously opened, it
[the delete] works fine". Is that still true (after importing into a new
db)?

HTH,
TC


Daniel Magnus Bennét Björck said:
Hi!

Yes, it is trying to delete other forms, not itself. Compacting/repairing
does not help.

Brgds

Danny
form
is be
that
 
M

MacDermott

Here's the code that worked well in Access 97, mostly under Windows98.

My memory is that I ran into some problems with Access 2000 and Windows2000,
which I never bothered to resolve - could have just been permissions, could
have been something else.

I was/am VERY grateful to Dev Ashish for supplying this!

- Turtle

Public Function DeleteForm(FormName As String, MDBpath As String)
' Code courtesy of Dev Ashish

On Error GoTo Err_Handler

Dim objAcc As Access.Application
Set objAcc = New Access.Application
With objAcc
.OpenCurrentDatabase MDBpath
.DoCmd.DeleteObject acReport, FormName
.CloseCurrentDatabase
End With

Set objAcc = Nothing

DeleteForm = True

Exit_Here:
On Error Resume Next
objAcc.Quit
Set objAcc = Nothing
Exit Function

Err_Handler:
DeleteForm = False
Select Case Err.Number
Case 3011: 'Form doesn't exist
MsgBox "The form '" & FormName & "' does not exist" _
& " in database " & vbCrLf & MDBpath & ".", _
vbExclamation + vbOKOnly, FormName & " not found"
Case Else
MsgBox "Error#:" & Err.Number & vbCrLf _
& "Description: " & Err.Description, _
vbOKOnly + vbCritical, "Runtime error: DeleteForm"
End Select
Resume Exit_Here

End Function
 
D

Daniel Magnus Bennét Björck

Hi!

Unfortunately I get the same result as with the code I tried myself; 2501:
The DeleteObject action was canceled.

Any, any, ANY other ideas ANYONE? I'm getting desparate.

Brgds

Danny
 
D

Daniel Magnus Bennét Björck

Hi!

I have found the problem now! For some reason it doesn't work if the second
form (the one that closes and deletes the first form) is opened as a Dialog
window!

Thank you for your help.

Brgds

Danny
 
D

Daniel Magnus Bennét Björck

Unfortunately, I just thought that was it, as I was able to reproduce the
problem in a smaller test database that way. However, after changing the
forms to not be opened in Dialog mode in the original database, I'm still
having the same problem...

Anyone???

Brgds

Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top