Lockout if table mis-spelled

Malcy

Registered User.
Local time
Today, 09:12
Joined
Mar 25, 2003
Messages
584
I am having a spot of bother with getting locked out of Access if any of the references to tables as DAO recordsets is wrong. It starts off with the normal "cannot find xxx" but when you click OK I get a new box "Object variable or with block variable not set"
You can hit the OK button till you are blue in the face but the only way I seem to be able to get out of it is to invoke Task Manager and end Access.
Partly it is my own fault in that in one database I have used a table name lblActivitiesLog but latterly I have been using the name tblActivityLog. If I copy a form from the wrong database and pop it into the new one and do not remember to check the reference and change it from
Code:
    Set rstAct = dbs.OpenRecordset("tblActivitiesLog")
to
Code:
    Set rstAct = dbs.OpenRecordset("tblActivityLog")
I get the problem
Is there any error trapping I could do to try and work around this
Any thoughts would be really appreciated.
 
Did you put an error trapping routine in the module?
 
Err
Nope. Have not usually found too great a need for one but perhaps I have been lucky so far!
What I do have is the basic
Code:
Err_cmdChLCancel_Click:
    MsgBox Err.Description
    Resume Exit_cmdChLCancel_Click
Confess I would not be sure how to start but more than willing to learn if you could point me.
Thanks
 
In the code you posted 'err' is and object. Just like a form or a textbox, it has properties. When Access hits and error in your code, it uses the object to, among other things, store information about the error. So the 'err.description' will return what ever has been stored in the err objects description property. So I'm guessing the error message you're seeing is a direct result of this. err.description is simply a text string that is being displayed by the msgbox function. There is another err object property called 'number'. To use it you you simply use 'err.number'. Just like the err.desription property, you can use it with the msgbox function to see waht the error 'number' is.

So... Try putting that line in you code (msgbox err.number) right after the line with 'MsgBox Err.Description' and run your code. You should get a second message this time with a number.

So... Now that you know what the error number is you cade code for it with something like the following in your error checking routine:

Err_cmdChLCancel_Click:
if err.number = XYZ then
Whatever
End if

???
 
Thanks Ken
That gives me an error code of 3078 but again as soon as I click on the <OK> button on that error message I am back in the "Object variable or with block variable not set" loop.
Somehow I need it to be a bit more graceful if a table name is mis-spelt, at least during my development and testing cycle!
I am not sure, however, how to do this.
I now think what is happening is that when it hits my exit code after the error message
Code:
Exit_cmdChLCancel_Click:
    rstAct.Close
    Set rstAct = Nothing
    Set dbs = Nothing
    stDocName = vbNullString
    stLinkCriteria = vbNullString
    Exit Sub
It then tries to close the recordset that it cannot open so throws wobble.
 
Did you include the resume statement in your error routine?
 
Hi Ken
Sorry. Been away playing in the hills with my Defender 90 for the weekend!
The error procedure is as shown in post 3 which to my untutored eye looks like it has the resume statement in it but all may not be what it seems.
Best wishes
 

Users who are viewing this thread

Back
Top Bottom