-
new form per vba -> err 29068
Hi experts,
there is something fishy around forms and vba (Access 2003).
I'm trying to create a new temporary form in vba. Its purpose is to show a dynamically generated table, allow the user to edit it and eventually to update data sources for this table. The table has a varying structure, therefore the form as well. After surving its purpose, the form is no longer needed and has to be deleted.
The form consists of some controls for displaying its RecordSource (generated on the fly accordingly with the table structure) and CommandButtons.
As long as no CommandButtons (and hence form-Module) are concerned, it works fine with CreateForm, CreateControl etc.
After introducing them however the behaviour of the Daba becomes unpredictable.
I'm drawing on the help example for creating an CommandButton and assigning an event routine to it.
Dim mdl as Module, ctrl as Control, lng
set mdl=frm.Module 'frm is my new form, already created
set ctrl=CreateControl(frm,acCommandButton, ....)
lng=mdl.CreateEventProc("Click",ctrl.Name)
mdl.InsertLines lng +1 , "MyHandlingProc"
docmd.Save acForm, frm.Name
docmd.Close acForm, frm.Name
docmd.Rename "MyFormName",acForm,frm.Name
And now it starts.
1) If any other form is opened, the docmd.Close fails with error 29068.
(cannot complete this operation. You must stop the code and try again.)
1a) Although if docmd.Save is commented out and docmd.Close comes with acSavePrompt, it works
1aa) However, docmd.Close .. acSaveYes does not work.
2) If no other form is opened, the form is saved, closed and renamed as intended.
I can even open it. What I can't do is to delete it. In the two-liner:
docmd.Close acForm, "MyFormName"
docmd.DeleteObject acForm, "MyFormName"
the second line throws an error "can't delete an open object"
3) Most peculiar of all this, some of the temporary forms, generated at the developing stage and the deleted manually, do not disappear altogether. They are no longer seen in the forms-window, but they are still present in the module-section, mostly under queery names like "~tmplcp208932". And one can switch to such a form itself from the module window (using "show object"), although, as already mentioned, no such form is listed under forms.
If I then delete it with
docmd.DeleteObject acForm, "~tmplcp208932"
I again get my favorite error 29068 (cannot complete this operation...). The error message being closed, the form disappeares in the module list.
So. Could anybody enlighten me, what's chemistry is at work here? I guess it's about how Access administrates its forms internally.
Thanks in advance
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules