Connecting Tech Pros Worldwide Forums | Help | Site Map

Object Variable question

yamafopa
Guest
 
Posts: n/a
#1: Nov 12 '05
Just moving up from Access 97 and trying 2K. I am used to using the
FindFirst method of the RecordsetClone object in order to do form
navigation with a combo box. I notice that the wizard in 2K writes the
following code in order to accomplish this...

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.Find "[req_no] = " & Str(Me![Combo98])
Me.Bookmark = rs.Bookmark

Set rs = Me.Recordset.Clone

My questions are;

1. Why dim the recordset as Object rather than as ADODB.Recordset?
2. Why not use rs.close and/or Set rs = nothing

If if was me doing this I would write...

On Error GoTo EH

Dim rst As ADODB.Recordset

Set rst = Me.Recordset.Clone
rst.Find "req_no = " & Str(Me!cboRequestCode)
Me.Bookmark = rst.Bookmark
rst.Close

SeeYa:
Set rst = Nothing
Exit Sub

EH:
MsgBox Err.Number & " - " & Err.Description
Resume SeeYa

Comments??

yamafopa!

Tom van Stiphout
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Object Variable question


On 31 Jan 2004 19:58:46 -0800, yamafopa@yahoo.com (yamafopa) wrote:

see comments in-line.
-Tom.
[color=blue]
>Just moving up from Access 97 and trying 2K. I am used to using the
>FindFirst method of the RecordsetClone object in order to do form
>navigation with a combo box. I notice that the wizard in 2K writes the
>following code in order to accomplish this...
>
> ' Find the record that matches the control.
> Dim rs As Object
>
> Set rs = Me.Recordset.Clone
> rs.Find "[req_no] = " & Str(Me![Combo98])
> Me.Bookmark = rs.Bookmark
>
> Set rs = Me.Recordset.Clone
>
>My questions are;
>
>1. Why dim the recordset as Object rather than as ADODB.Recordset?[/color]
Sloppy programming, or late binding. Note that with A2000 for the
first time ADO is the default, rather than DAO,

[color=blue]
>2. Why not use rs.close and/or Set rs = nothing[/color]
Sloppy programming. You're better off closing objects explicitly.
[color=blue]
>
>If if was me doing this I would write...
>
>On Error GoTo EH
>
>Dim rst As ADODB.Recordset
>
>Set rst = Me.Recordset.Clone
>rst.Find "req_no = " & Str(Me!cboRequestCode)
>Me.Bookmark = rst.Bookmark
>rst.Close
>
>SeeYa:
> Set rst = Nothing
> Exit Sub
>
>EH:
> MsgBox Err.Number & " - " & Err.Description
> Resume SeeYa
>
>Comments??
>
>yamafopa![/color]

MacDermott
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Object Variable question


This is a guess on my part, but I know that from A2K you can "Save as
previous version".
This code will run without change in A97.
If the declaration were specific to ADO (default for A2K) or DAO (default
for A97), there would be more problems moving between versions.
In fact, this code will run under any combination of references to ADO
and/or DAO.

As for closing rs, I've repeatedly seen the admonition:
If YOU open it, YOU should close it.
You're not opening rs - just setting it to point to an existing recordset.
So there's no need for you to close it.
And since it's declared local to your procedure, it will go out of scope
anyhow.

HTH
- Turtle

"yamafopa" <yamafopa@yahoo.com> wrote in message
news:86495029.0401311958.51e4e0f@posting.google.co m...[color=blue]
> Just moving up from Access 97 and trying 2K. I am used to using the
> FindFirst method of the RecordsetClone object in order to do form
> navigation with a combo box. I notice that the wizard in 2K writes the
> following code in order to accomplish this...
>
> ' Find the record that matches the control.
> Dim rs As Object
>
> Set rs = Me.Recordset.Clone
> rs.Find "[req_no] = " & Str(Me![Combo98])
> Me.Bookmark = rs.Bookmark
>
> Set rs = Me.Recordset.Clone
>
> My questions are;
>
> 1. Why dim the recordset as Object rather than as ADODB.Recordset?
> 2. Why not use rs.close and/or Set rs = nothing
>
> If if was me doing this I would write...
>
> On Error GoTo EH
>
> Dim rst As ADODB.Recordset
>
> Set rst = Me.Recordset.Clone
> rst.Find "req_no = " & Str(Me!cboRequestCode)
> Me.Bookmark = rst.Bookmark
> rst.Close
>
> SeeYa:
> Set rst = Nothing
> Exit Sub
>
> EH:
> MsgBox Err.Number & " - " & Err.Description
> Resume SeeYa
>
> Comments??
>
> yamafopa![/color]


Closed Thread