Kamis, 07 Februari 2013

[MS_AccessPros] Re: run-time error '91' object variable or with block variable

 

Crystal,
Thanks for the help. I'm trying to learn VBA and don't really understand what all is going on yet. I know you need to have error handling.

Can you give me an idea of what my current code should look like without adding the additional code? John V is also helping me.

Thanks,

John F.

--- In MS_Access_Professionals@yahoogroups.com, Crystal wrote:
>
> Hi John,
>
> >"Dim db As DAO.Database, rst As DAO.Recordset"
>
> the value of public variables is lost on an unhandled error.  This would cause an error when the object variable is not defined  If you are going to use this method to persist a connection, make sure that all code has error handlers.  If you don't feel like going through every procedure to add error handling, you can use something like Wayne Phillips vbWatchdog, which is a Global Error Handler and Tracing utility that you enable in code that runs when the database opens.  www.everythingaccess.com/vbwatchdog.htm
>
> this is my standard error handling code:
>
> '~~~~~~~~~~~~~~~~~~~~~~~~~
> Sub ProcedureName
>
>    On Error GoTo Proc_Err
>    '
>    ' statements of the procedure
>    '
> Proc_Exit:
>    On Error Resume Next
>    'release object variables
>    if Not rs is Nothing then
>       rs.close
>       set rs = Nothing
>    end if
>    set db = nothing
>    Exit Sub ' or Function
>  
> Proc_Err:
>    MsgBox Err.Description, , _
>         "ERROR " & Err.Number _
>         & "   ProcedureName (CHANGE THIS) "
>
>    Resume Proc_Exit
>    Resume
> '~~~~~~~~~~~~~~~~~~~~~~~~~
>
> http://www.AccessMVP.com/strive4peace/Code.htm
>
>
> Warm Regards,
> Crystal
>
>  *
>    (: have an awesome day :)
>  *
>
>
>
>
>
> ________________________________
> From: jfakes.rm
> To: MS_Access_Professionals@yahoogroups.com
> Sent: Wednesday, February 6, 2013 1:10 PM
> Subject: [MS_AccessPros] run-time error '91' object variable or with block variable
>
> When I open one of my databases normally (not shift enter), when I click on the exit access command on the menu, I get a "run-time error '91' object variable or with block variable." 
>
> I finally figure out that it has something to do with a form I use to maintain a permanent connection to the back end.
>
> Following is the code for the form. Note:  tblKeepOpen is a linked table in the backend used to maintain the connection.
>
> Can someone please explain what I've done wrong here?
>
> Option Compare Database
> Option Explicit
> Dim db As DAO.Database, rst As DAO.Recordset
>
> Public rsAlwaysOpen As Recordset
> Private Sub Form_Close()
>     rsAlwaysOpen.Close
>     Set rsAlwaysOpen = Nothing
>    
>   End Sub
> Private Sub Form_Open(Cancel As Integer)
> 'Set rs = db.OpenRecordset("tblKeepOpen", dbOpenDynaset)
>     Set rsAlwaysOpen = CurrentDb.OpenRecordset("tblKeepOpen")
> End Sub
>
> John F.
>
> [Non-text portions of this message have been removed]
>

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (5)
Recent Activity:
.

__,_._,___

Tidak ada komentar:

Posting Komentar