Error Trapping and Autoexec (1 Viewer)

hudson426

Registered User.
Local time
Today, 10:43
Joined
Jun 19, 2009
Messages
28
Dear all

I'm totally lost and confused and need some help.

I send a db out once a month to over 200 users (it has to be a local copy). Because of the size of the file (and that outlook will not send .mdb files as attachments), I have to zip it up.

If the user doesn't unzip the file and he/she launches it directly from the zip file, they get the following error:-

"The database 'xxx' is read-only.

You wont be able to save changes made to data or object definitions in this database"

I've done some research and this is error number 8400

What I want to happen is this:-

If.... database is opened as read only
Then.... give a message "Please detach database from zip file before opening" and then quit
Else.... run the autoexec macro

I've tried numerous permutations of error trapping but I can't for the life of me get it to work. Probably because this is my first attempt at error trapping!

Any help and guidance would be greatly appreciated

Cheers

p.s. Using MS Access 2003
 

mdlueck

Sr. Application Developer
Local time
Today, 05:43
Joined
Jun 23, 2011
Messages
2,631
I recreated the situation you are describing by setting the Read-Only attribute on a test database.

The warning message you describe indeed comes up, however it is Access itself and nothing detectable via code.

What's more, probably the source directory is not in the trusted directory list, so code will be disabled until they click to allow code execution.
 

jamesmor

Registered User.
Local time
Today, 04:43
Joined
Sep 8, 2004
Messages
126
could you possibly put it in a self-extracting zip file?

I haven't had to deal with zipping in a long time because I just pass copies via the network, but back when I had to I "remember" using self extracting zip files.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:43
Joined
Sep 12, 2006
Messages
15,696
if you know the error, can you just not trap the error

maybe in your startup procedure, try and write a value in a dummy table, to see if the dbs is read only.
 

hudson426

Registered User.
Local time
Today, 10:43
Joined
Jun 19, 2009
Messages
28
Mdleuk & Jamesmore - Thanks for this, I'll do some more digging.

gemma-the-husky - My db opens a form and then writes some values at start up.

This is what happens when I open my db directly from a zip file:-

Security Warning - OPEN (to continue)

Message - The database 'xxx' is read-only.

You wont be able to save changes made to data or object
definitions in this database

OK (to continue)

Form Opens

Message - Operation must be an updateable query

OK (to continue)

Message - Action Failed
Macro Name - Auto Exec
Condition - True
Action Name - OpenQuery
Arguments - search type reset, Datasheet, Edit

Halt to continue

When the user opens it direct from a zip file, the db is automatically put into 'read only' state. How do I detect that it's read only, advise the user on what to do and close the db?

The 'read only' message doesn't come up with an error number (although I did a google search and found that it is error 8400)

Any suggestions???
 

jamesmor

Registered User.
Local time
Today, 04:43
Joined
Sep 8, 2004
Messages
126
In your error trapping, have a message box spit out the error number like the following

Code:
On err goto errHandler

errHandler:
msgbox err.number

this will let you validate the error number you're getting.

then you can do a "Select Case" on the error number and display whatever message you want to the end user.

The difficult part would be getting the error trapping code in the right section, I'd start with it being in the form open event.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:43
Joined
Sep 12, 2006
Messages
15,696
hudson - what i am saying is BEFORE opening the start up form do something like this


Code:
on error goto fail
currentdb.execute "update tbldummy set somefield = 1"
exit sub
 
fail:
msgbox("sorry - dbs not updateable etc")
quit application
 

mdlueck

Sr. Application Developer
Local time
Today, 05:43
Joined
Jun 23, 2011
Messages
2,631
The 'read only' message doesn't come up with an error number (although I did a google search and found that it is error 8400)

Any suggestions???

Like I said after I did a quick test... I think you are going to be stuck as the error comes on the screen PRIOR to any code execution.

Further complication would be that probably the zip file temp directory path will not be in the trusted directory list, so there again code will not be allowed to execute. I did my testing with a database in a trusted directory, so this did not apply in my case.
 

hudson426

Registered User.
Local time
Today, 10:43
Joined
Jun 19, 2009
Messages
28
mdleuk - I've been reading up on trusted directories and this is a big factor. If I cannot get any other solution to work, then I'll just have to educate the users. Again! I've tested a self executing zip file, but it saves it as an .exe file and Outlook wont let me sent .exe files. Bugger!

gemma-the-husky - I'm getting somewhere with your suggestion. Please find example attached. It's crude, but highlights the principle.

If anyone can figure out a way to remove the warning messages ('Read only" & "Action Failed"), I'd be extremely grateful.

If you open the zip file and launch it directly from there, you'll see the messages before the msgbox and then the db quits.

If you open the .mdb file, this is what is supposed to happen when all is OK.

Thank you all so much for your help so far! :)
 

Attachments

  • error trap.zip
    16.9 KB · Views: 87
  • error trap.mdb
    228 KB · Views: 91

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:43
Joined
Sep 12, 2006
Messages
15,696
Last edited:

mdlueck

Sr. Application Developer
Local time
Today, 05:43
Joined
Jun 23, 2011
Messages
2,631
I've tested a self executing zip file, but it saves it as an .exe file and Outlook wont let me sent .exe files. Bugger!

Because "self-extracting zip" = ".exe program file" which could contain a virus.

And some ISP's would not allow a .exe attachment for the same reason.
 

hudson426

Registered User.
Local time
Today, 10:43
Joined
Jun 19, 2009
Messages
28
mdlueck - Yeah, I had an inkling that was the reason. Oh hum!

gemma-the-husky - Thank you ever so much for the example. Does exactly what I need.

I am very grateful for everyones help on this, couldn't of managed it without you.

Anyone know of a way to ensure users read, understand and implement simple instructions? Ha ha

Cheers everyone

H
 

Users who are viewing this thread

Top Bottom