Cannot refer to form controls after coded change to acDesign and back to acNormal

pondlife

Registered User.
Local time
Today, 09:13
Joined
Apr 27, 2007
Messages
49
My ACC2000 form has some controls that on the OnCurrent event are conditionally made invisible. I also need to adjust the page margins programmatically. In ACC2000 this must be done using PRTMIP which necessitates loading the form in design view (DoCmd.OpenForm frmMyForm, acDesign) setting the margins, then returning to normal View (DoCmd.OpenForm frmMyForm, acNormal) to print it. When the form returns to normal view (1) the controls that had been made invisible reappear (ok, not a problem) and (2) further code to make them invisible returns 'the expression you entered refers to an object that is closed or doesnt exist'. What the blooming heck is going on?
(Notes: This happens whether the controls are referred to in (2) in the Me.Control syntax or Forms("MyForm").Controls("MyControl") syntax. The code for adjusting the margins I have adapted from http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_20831908.html )



I really would appreciate some help with this!
 
Last edited:
Why are you print a form and not a report?

My guess is that using a report would probably solve a lot of your issues.

Have you tried completing closing the form and then open it, ( not just switch modes)?
 
Thanks for your suggestion. Before I try the report alternative (a fair amount of work and no particular guarantee of success) I'm hoping someone will come up with the reason for this strange behaviour as a form.
 
i agree with hitechcoach

forms can be printed, but often don't format properly, and wont paginate easily

I would use a report - its not hard at all
 
I have no trouble formatting this form for printing, except for this one issue, and there are benefits from keeping it as a form.

Can anybody lead me to an understanding of why changing views in code causes a form to be unable to address its controls?
 
I
Can anybody lead me to an understanding of why changing views in code causes a form to be unable to address its controls?
I find the same issue when not using VBA code when switching modes. Did you see the last sentence in my original post? Did you try that?
 
I need to open the form at particular record called by another form so (1) open the form in design view, make the page margin changes, save it, close it (2) open the form from the other form at the required record and print it. That should work. I'll have a go tomorrow.
 
Last edited:
I would guess that when you switch to design mode, that instance of the form goes dead, when you switch back you are not talking to the new instance, but to the old dead instance.

Evan
 

Users who are viewing this thread

Back
Top Bottom