Runtime error 29068 when try to delete a form using VBA in Access2010 (1 Viewer)

seeking

New member
Local time
Today, 11:51
Joined
Dec 17, 2010
Messages
7
Hi all,

I tried to delete a form using VBA in Access2010. The code is like this

DoCmd.DeleteObject acForm, strFromName

But I got runtime error 29068 "cannot complete this operation. You must stop the code and try again"

The same code works well in Access97. I don't know what happened.

Could somebody here help me out? Appreciate it a lot
 

boblarson

Smeghead
Local time
Today, 11:51
Joined
Jan 12, 2001
Messages
32,059
Is the form open? It can't be. It also can't be running from the form you want deleted.

Why would you have code to delete a form? That strikes me as a database which might not have been properly designed. What would the purpose be?
 

jollymike

New member
Local time
Today, 13:51
Joined
Mar 11, 2011
Messages
1
I am have the same problem. I have created code within a function to delete a form object and am calling that function from a button on a form. The form I am attempting to delete is not open at the time I run the code.

My purpose in deleting a form with code is to automate the process of importing forms from another database.

DoCmd.DeleteObject acForm, "Form A"
DoCmd.TransferDatabase acImport, "Microsoft Access", "Location of db", acForm, "Form A", "Form A", False

This code is repeated many times to delete and import many forms.

*Note: I am using Access 2007
 

Thales750

Formerly Jsanders
Local time
Today, 14:51
Joined
Dec 20, 2007
Messages
2,102
Is the form open? It can't be. It also can't be running from the form you want deleted.

Why would you have code to delete a form? That strikes me as a database which might not have been properly designed. What would the purpose be?



I just tried it and it worked fine for me.

Corection, I just tried it on a Table and it worked fine. Not forms
 
Last edited:

Thales750

Formerly Jsanders
Local time
Today, 14:51
Joined
Dec 20, 2007
Messages
2,102
This works on Tables without halting, but not on forms.

Code:
Private Sub Command54_Click()
 
 
    Dim db As Database, rst As Recordset
    Dim rs As DAO.Recordset
    Dim stDocName As String
    Dim stDeleteObject As String
 
    Dim stObjectType As String
 
 
  Set Mydb = DBEngine.Workspaces(0).Databases(0)
 
Set rs = Mydb.OpenRecordset("qryDeleteAllObjects", dbOpenDynaset)
DoCmd.SetWarnings False
    rs.MoveFirst
    Do Until rs.EOF
 
 stDeleteObject = rs!ObjectName
 stObjectType = rs!ObjectType
 
If stObjectType = "acTable" Then DoCmd.DeleteObject acTable, stDeleteObject
If stObjectType = "acQuery" Then DoCmd.DeleteObject acQuery, stDeleteObject
If stObjectType = "acForm" Then DoCmd.DeleteObject acForm, stDeleteObject
If stObjectType = "acReport" Then DoCmd.DeleteObject acReport, stDeleteObject
 
  rs.MoveNext
      Loop
 
DoCmd.SetWarnings True
 
 
End Sub

I get the same thing error 29068 but after you push ok it goes ahead and deletes the form. Weird.

Access 2007
 

Thales750

Formerly Jsanders
Local time
Today, 14:51
Joined
Dec 20, 2007
Messages
2,102
This is what I found here:

http://www.office-forums.com/run-time-error-29068-deleting-modules-t683477.html




haven't tried it :~)

But I will be surprised if you are able to delete modules in the
current project.

Deleting a module puts the project in a de-compiled state. The
code can't run when the project is in a de-compiled state: it needs
to re-compile. The project can't re-compile while you are running
code: you need to stop the code and try again.

Try changing the VBA properties so that it does not automatically
compile (this is opposite to the usual recommendation).

Try using a separate Access.Application object, so that you can
run the code in one Application object, to delete the modules in
a different Application object.

(david)

So I'm guessing the same thing when it tries to do forms. Something about the module being deleted requires a recompile.

Any ideas?
 

Thales750

Formerly Jsanders
Local time
Today, 14:51
Joined
Dec 20, 2007
Messages
2,102
The way I will try to fix it tomorrow is to trap the error and set the value of a public variable to true, and then exit sub . Next I'll set the timer to rerun the code in about 250 ms, after it has run the code enough times to delete all the forms and reports it will exit naturally, reseting the public variable to false.

Its unorthodox.
 

Users who are viewing this thread

Top Bottom