Multiple OutputTo (Called on Closing Form) Fails on Closing Database

J

John Andrews

I have a created a macro which executes on closing the main data entry
form of a database. The user is supposed to close the database at the
and of the day which causes the form to close and the macro to be
executed. The macro works fine in testing when just the form is closed
but the database remains open. However when the form is force closed
via database closure the macro seems hobbled. It works like this:

Four different rtf files are created via OutputTo from a report which
gets it's parameters from a form which is filled out systematically
(SendKeys) by the macro with predefined parameters. The problem is
that though four reports are created they are all the same (first)
report. I'd appreciate a solution to this which ideally does not
involve modules. Thanks in advance. Sequence below:
RunApp (Calls batch file to delete the previous day's rtfs)

OpenForm
GoToControl
Send Keys (First parameter)
OutputTo (First rtf)
Close (Close Form without saving)
Close (Close Report without saving)
OpenForm
GoToControl
Send Keys (Second parameter)
OutputTo (Second rtf)
Close (Close Form without saving)
Close (Close Report without saving)
OpenForm
GoToControl
Send Keys (Third parameter)
OutputTo (Third rtf)
Close (Close Form without saving)
Close (Close Report without saving)
OpenForm
GoToControl
Send Keys (Fourth parameter)
OutputTo (Fourth rtf)
Close (Close Form without saving)
Close (Close Report without saving)
 
N

Nikos Yannacopoulos

John,

I'm only guessing here, but the first thing that looks suspect is the
SendKeys actions; SendKeys is known to produce unexpected results onve too
often, simply because it does what the name implies regardless of what is
going on in the environment, so it can easily end up sending the keystrokes
to the wrong place at the wrong time.

My suggestion is you start by replacing each:

GoToControl
Send Keys (Fourth parameter)

by:
SetValue args: Item = Control Name, Expression = value

HTH,
Nikos
 
J

John Andrews

Nikos,

Thank you so much. I've cleaned up the sequence considerably following
your advice and it now runs like a dream. You've opened my eyes to the
perils of SendKeys - I hope never to have to use it again!

I've only just discovered this group and it's been of great help.
BW
John
 
N

Nikos Yannacopoulos

John,

Glad to have helped. As far as I'm concerned (and I'm sure many would
agree), SendKeys is to be avoided at any cost. Almost anything it's used for
can be done in much more robust ways in a macro (yours is an example), and I
would remove the "almost" part when it comes to VB code. I'm a code person,
and once I discovered it I never went back to macros (again, I suppose I'm
not an exception in that), it opens wide new possibilities and offers far
better control, so I encourage you to give it a shot if you're willing to,
and promise you'll never regret it. A good starting point to get a first
feeling of it, is to have Access convert your existing macros to code, so
you can go through it knowing what it's supposed to do, and relate back to
the macro actions.

Good luck,
Nikos
 

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