Try:
Dim rs As DAO.Recordset
If that line generates an error, it is a references issue. Details:
http://allenbrowne.com/ser-38.html
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
"phappyman" <member39626@dbforums.com> wrote in message
news:3372166.1063645294@dbforums.com...[color=blue]
>
> Thanks, but that isn't the problem. I built the test sub just to make
> absolutely sure that what I was writing happened. The reason why I
> forgot the "Exit Sub" line is because my subroutine *never got that
> far*. Here is the (updated) subroutine:
>
>
>
> Public Sub CloseRecordset()
>
> On Error GoTo Sub_Error
>
> Dim rs As Recordset
>
>
>
> rs.FindFirst "This Will Error"
>
>
>
> Sub_Exit:
>
> On Error Resume Next
>
> rs.Close
>
> Set rs = Nothing
>
>
>
> Exit Sub
>
>
>
> Sub_Error:
>
> GoTo Sub_Exit
>
> End Sub
>
>
>
>
>
>
>
> The problem is the same as before, but the obvious (unrelated) error has
> been fixed.
>
>
>
>
>
> Pete
>
>
>
>
>
> Original question:
>
>
>[color=green]
> > I'm trying to improve my code so that when I open a recordset object,[/color]
>[color=green]
> > I can absolutely guarantee it is closed and is set = Nothing. I have[/color]
>[color=green]
> > read some old threads and they all say to use the functional[/color]
>[color=green]
> > equivalent of the following code:[/color]
>[color=green]
> > Public Sub CloseRecordset()[/color]
>[color=green]
> > On Error GoTo Sub_Error[/color]
>[color=green]
> > Dim rs As Recordset[/color]
>[color=green]
> > rs.FindFirst "This Will Error"[/color]
>[color=green]
> > Sub_Exit:[/color]
>[color=green]
> > On Error Resume Next[/color]
>[color=green]
> > rs.Close '<----"Object variable or with block not set"[/color]
>[color=green]
> > Set rs = Nothing[/color]
>[color=green]
> > Sub_Error:[/color]
>[color=green]
> > GoTo Sub_Exit[/color]
>[color=green]
> > End Sub[/color]
>[color=green]
> > However, *THIS CODE DOES NOT WORK*. It should attempt to "rs.Close"[/color]
>[color=green]
> > and fail, and move to the next record as dictated by the "On Error[/color]
>[color=green]
> > Resume Next" line. But it doesn't; it pops up the Debug/End/Help box[/color]
>[color=green]
> > here (the default error handling).[/color]
>[color=green]
> > I'm using Access 97, and yes, this is cut/pasted directly out of my[/color]
>[color=green]
> > test function. I understand that originally, I have it go to[/color]
>[color=green]
> > Sub_Error whenever an error occurs. When I get to the exit
> > point (the[/color]
>[color=green]
> > Sub_Exit label), it should switch to the "resume next" behavior, but[/color]
>[color=green]
> > instead apparently resets the error trapping to default. What am I[/color]
>[color=green]
> > doing wrong?[/color]
>[color=green]
> > Pete[/color]
>
>
> --
> Posted via
http://dbforums.com[/color]