Errors not being trapped.

irish634

Registered User.
Local time
Today, 14:44
Joined
Sep 22, 2008
Messages
230
I have a weird problem I can't seem to get a grasp on.

I have a split database in Access2K. I have the code below to check the link to the backend:
Code:
Function Check_Links() As Boolean
On Error GoTo Error_Handler
    
    'Checks for the connection to the backend
    
    Check_Links = False
        
    Set rst = CurrentDb.OpenRecordset("dbsystbl_DLLFiles")
    If rst.RecordCount > 0 Then
        Check_Links = True
        rst.Close
        Set rst = Nothing
    End If

    
    
Error_Handler_Exit:
    Exit Function
   
Error_Handler:
    Set rst = Nothing
    Check_Links = False
    DoCmd.OpenForm "frm_LinkDatabase"
    DoCmd.Close acForm, "frm_MainMenu"
    Err.Clear
    Resume Error_Handler_Exit
    
End Function
My problem is, when the backend isn't there, I get a runtime error (3024) that breaks on this line: "Set rst = CurrentDb.OpenRecordset("dbsystbl_DLLFiles")"

Now the weird part is, this used to work. It would trap the error and open the frm_LinkDatabase.

I don't understand why my error is not being trapped now. Does anyone have any suggestions?
 
Last edited:
How have you declared rst?

Dim rst As DAO.Recordset

Also you need to move the Set rst = Nothing outside of the If statement as it will never be released if the table exists.

Also after the Set rst instead of diving straight in asking for the RecordCount you first need to check for EOF and BOF then do a MoveLast

Code:
Dim rst As DAO.Recordset
Dim rCnt as Integer

Set rst = CurrentDb.OpenRecordset("dbsystbl_DLLFiles")

If Not rst.EOF And Not rst.BOF Then
   rst.MoveLast
   rCnt = rst.RecordCount
   rst.Close
End If
Set rst = Nothing

Code:
If rCnt > 0 Then
    Check_Links = True
End If


Note:You may need to reference Microsoft DAO Oject library via Tools and References
David
 
Thanks for the reply David.

To answer your questions:

  1. Yes "rst" is declared - I have a separate module where I declare my most common items: e.g., "Public RST as DAO.Recordset". That is ok.
  2. DAO is referenced properly.
Now I am really puzzled. I used your code, and now the error is being trapped again.

The way it's designed is if there is an error on this line e.g, table missing:
Set rst = CurrentDb.OpenRecordset("dbsystbl_DLLFiles") it's suppose to go to the error handler and open my form to connect to the BE.

So if the table was missing, it would never reach the code where it's looking for the record count.

Our codes use the same line that produces the error I want. What's puzzling to me is why the error was not being trapped, and now it is.

Now for the extra puzzling part, my original code works fine now too. It traps the error as designed.

So my question still exists: what caused the error handler not to work?

Regardless, I like your code better than mine so I'll use it. Thanks.
 
Last edited:
Don't know how your other code works but here is a Link to a sample database that checks for linked tables via a user login screen. there may be some code of interest in there for you.

David
 
Thanks. I'll have a look at that too.

I'm pretty bamboozled now as to why everything started working again. But since it does, now I can go back to my development.

I'm still going to use your code because it makes sense to do it that way.
 
perhaps your code never ran the check_links function, because of some other error

when tracing stuff like this, setting breakpoints is useful, as you can step through code, and see whats happening at a micro-level
 

Users who are viewing this thread

Back
Top Bottom