OnClose Problem

T

TommoUK

I have a problem that should be simple to sort out but I am banging my head
at the moment!

I have a routine that runs fine. The last thing this routine does is open up
a form in datasheet view. The users can then amend or add to the data. I have
set the "OnClose" event to call a function that outputs the file to Excel. If
I run this function on it's own, it works fine. If I run the full procedure
and then close Access down, again, it works fine. However, if I run the
routine, the form opens up but then when I close it, the output function does
not run.

Help!!!!!!!!!!
 
J

Jeanette Cunningham

Hi Tommo,
the close event is the (almost) last thing for the form and is usually too
late to run significant code. Put your code on the unload event instead of
the close event.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
T

TommoUK

Thanks for the quick reply Jeanette but this doesn't work either. I've tried
running the output procedure using the "RunCode" within an embedded macro,
and I have also tried running it using "Call".
 
J

Jeanette Cunningham

Step through the code to find out where it goes wrong.
Create a break point at the start of the code for the output to routine.
Click in the code at the far left margin opposite the start of the routine.
You should see a big dot in the margin and the text highlighted.

Close form and open normally.
Do whatever is needed to make the output routine run.
When your code gets to the break point, the debug window will open.
You can press the F8 key to go through the code one line at a time.

Watch where the code goes, maybe it skips some of the code.
Maybe there is a run time error.

if the code never starts the output to routine, you may need to change the
break point to the on close event or the unload event or which ever event
calls the output to routine.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 

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