Code runs only when traced

  • Thread starter Thread starter Joe Holzhauer
  • Start date Start date
J

Joe Holzhauer

I'm struggling with some strange behavior by Access 2003:

I have a Form_Resize event procedure that calls the sub ResizeControls. The
ResizeControls sub (obviously) resizes several controls on the form to fit
the new form size. I maximize this form on open, so the code should run
automatically.

The problem is that when I click the command button I have on another form
to open the form in question, none of the controls are resized--it's like
the code doesn't run. What's weird is that when I set a bookmark and trace
through the code, it works perfectly.

Has anyone encountered this before? Code that works perfectly when
debugging, but not when running?

Thanks for any ideas you might have!
Joe
 
Yes, I've run into this before myself. It also happens when you try to
export reports one after the other, you get an error when running it normally
but can step through it just fine. My workaround has been to set the active
form not visible then switch it back, that seems to give everything enough
time to catch up and execute properly. So it's

me.visible = false
me.visible = true

right before any piece of code you are having problems with. The user will
just see a slight flicker when this happens.
 
Since it works when you trace through the code, it sounds as if there is a
timing problem. It may be that the previous code hadn't finished yet. Place
a Debug.Print statement in the ResizeControls procedure to see if the code
is being skipped or just not doing what you want, something like

Debug.Print "ResizeControls, Got here!"

If that is in the Immediate Window, then the code is running. You may want
to try a DoEvents command at the start of the procedure to let other things
finish before the procedure runs. This may or may not help. You may also try
DoEvents right after the OpenForm call to see if that helps.
 
I have also come across this problem a few times before.

It has been solved by inserting the DoEvents command which seems to allow
processing to catch up.
 
Joe said:
I'm struggling with some strange behavior by Access 2003:

I have a Form_Resize event procedure that calls the sub ResizeControls. The
ResizeControls sub (obviously) resizes several controls on the form to fit
the new form size. I maximize this form on open, so the code should run
automatically.

The problem is that when I click the command button I have on another form
to open the form in question, none of the controls are resized--it's like
the code doesn't run. What's weird is that when I set a bookmark and trace
through the code, it works perfectly.

Has anyone encountered this before? Code that works perfectly when
debugging, but not when running?


It's remotely possible that the form controls have been
resized, but they have not been redrawn on the screen.

Sometimes DoEvents is sufficient, but sometimes using
Me.Repaint is all it needs. On occasion, you actually need
both.
 

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

Similar Threads


Back
Top