Avoiding disaster

  • Thread starter Thread starter google3luo359
  • Start date Start date
G

google3luo359

There are a couple of things that could bring my db down to its knees
and they would be due to user error. I'm wondering how I can best avoid
these disasters.

One section of VB code is to be run just once a year.
For it to be successful the user must have prepared a .txt file that
has been formatted correctly. It also must be placed in the proper
folder, ready to be imported.

Incorrect formatting or the wrong location for the file would render
the db unusable. Apart from telling the user about this and using
reminder notes during operation, is there another way to protect from
these disasters?

For example is there a way to check that the file is in the correct
location and if not bring up a warning message?

Also, I have an import spec for the file. Is there some way to check
that the file is in the correct formatting, before/after it is
imported?

TIA Ric
 
Interesting. I think I'd create a table and a form the user can enter the
necessary info into, then set code to dump that info out to a report, output
to a text file.

Something like:

Dim file as string
file = "C:\Temp\MyInput.txt" 'Or whatever - use full path and file
name with quotes
DoCmd.OutputTo acOutputReport, "YourOutputReport", "MS-DOSText(*.txt)", file

You will probably want to use a temporary table, and clear it in the OnOpen
event of the form, so that you don't have more than one record outputting to
your spec file.
 
It sounds like you'd trigger an error condition if the prerequisite(s)
wasn't met.

One way to handle this is to add in an exception in your error handling
code. The generic idea is: "If something breaks, start processing the
error message ... but if the error number is #####, handle this other way."

You'd have to have error handling code in place, or create it, for this
approach to work.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Hi Susan,

Thanks for your reply.
I should explain myself a little better as I don't think your
suggestion would work as it stands, in my case.
The .txt file will likely be prepared by a secretary. It will contain
approx. 700 student numbers, names, and grade levels. That file must be
in the correct format (CSV) and fields in the correct order.
All that's required is that this file be imported into the db once a
year at the beginning of September.

Ric
 
Jeff said:
It sounds like you'd trigger an error condition if the prerequisite(s)
wasn't met.

One way to handle this is to add in an exception in your error handling
code. The generic idea is: "If something breaks, start processing the
error message ... but if the error number is #####, handle this other way."

You'd have to have error handling code in place, or create it, for this
approach to work.

Hi Jeff,

Currently I've removed pretty much all error messages, I guess I'd
like the best of all worlds (not confuse the user, but bring up an
error in an important situation such as I'm now describing).

How can I find out the error number for each error that can occur?
Right now there's just basic On_error code in the db.
I wouldn't know how to trap for an error number.

TIA Ric
 
Sorry I should explain a bit more.
When I said I've removed most error messages, i was meaning the notices
you receive when you run a query and it says eg. "You are about to run
this query, 305 records are about to be deleted.... etc..."
I've removed most of those.

Ric
 
Ric

If you run the routine when you DON'T have the prerequisites in place,
Access generates an error message, containing the error number.

Adding error handling to your procedures (subroutines, functions) gives you
a way to handle unexpected conditions. If you are using SetWarnings to turn
off warning messages, you are not handling errors.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Ah, yes, much different than I had thought. You could still use a form to
populate a table and export to csv, but perhaps that wouldn't work for you.

SusanV
 
Back
Top