473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Determining (in VBA) if a recordset is open

PW
Hi,

I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset open
and a database open isn't a good idea, right?

Thanks,

-paul w

Oct 31 '06 #1
23 52548
Once a recordset object and a database object go out of scope, VBA
automatically closes the objects, although, it is a good practice to
specifically close a recordset >rs.Close and set a database object to
nothing >Set DB = Nothing. It helps to further reduce the possibility
of a null pointer still on the stack (at the system level).

If you are using global variables for your objects, on the other hand,
these objects won't go out of scope when a procedure is finished using
them. In this case, if you don't close a recordset and try to reuse it
again in another procedure, then Access will complain. I find it best
to use Recordset objects at the local level (local to the procedure
using it.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Nov 1 '06 #2
PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.com:
I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset
open and a database open isn't a good idea, right?
The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

For db variables, I do the same, but without the close in cases
where the db variable is pointing to the MDB currently opened in the
Access UI. The .Close causes no problem when the variable is
initialized with CurrentDB() but can cause an error if you
initialized it with DBEngine(0)(0).

I do know that it's possible for a database variable to be Not
Nothing and not be open, and I'd assume that between the rs.Close
and the Set rs = Nothing that the variable is Not Nothing but
closed, but that's only going to happen once you've closed the
recordset. If you only do that in your cleanup, it oughtn't be an
issue.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Nov 1 '06 #3
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.com:
>I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset
open and a database open isn't a good idea, right?

The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

For db variables, I do the same, but without the close in cases
where the db variable is pointing to the MDB currently opened in the
Access UI. The .Close causes no problem when the variable is
initialized with CurrentDB() but can cause an error if you
initialized it with DBEngine(0)(0).

I do know that it's possible for a database variable to be Not
Nothing and not be open, and I'd assume that between the rs.Close
and the Set rs = Nothing that the variable is Not Nothing but
closed, but that's only going to happen once you've closed the
recordset. If you only do that in your cleanup, it oughtn't be an
issue.
It's unfortunate the recordset in question isn't an ADO recordset, I
suppose. Then we could just test its State property for

adStateClosed 0 Indicates that the object is closed.
adStateOpen 1 Indicates that the object is open.

and we'd know ... and a few other things.

adStateConnecting 2 Indicates that the object is connecting.
adStateExecuting 4 Indicates that the object is executing a command.
adStateFetching 8 Indicates that the rows of the object are being
retrieved.

But I suppose we can't expect
an obsolete technology to give us very much;
we just have to live with it, for a while that is, while it survives.

Of course if it were an ADO recordset, in this case we wouldn't have to
test it anyway as ADO pointers are gathered up in garbage-collection and
released without any intervention anyway.

I guess it's no wonder that DAO is kaput!

--
Lyle Fairfield

from http://msdn.microsoft.com/library/de...l=/library/en-
us/dnmdac/html/data_mdacroadmap.asp

Obsolete Data Access Technologies
Obsolete technologies are technologies that have not been enhanced or
updated in several product releases and that will be excluded from future
product releases. Do not use these technologies when you write new
applications. When you modify existing applications that are written
using these technologies, consider migrating those applications to
ADO.NET.
The following components are considered obsolete:
....
Data Access Objects (DAO): DAO provides access to JET (Access) databases.
This API can be used from Microsoft Visual Basic®, Microsoft Visual C++®,
and scripting languages. It was included with Microsoft Office 2000 and
Office XP. DAO 3.6 is the final version of this technology. It will not
be available on the 64-bit Windows operating system.
.....
Nov 1 '06 #4
On Tue, 31 Oct 2006 16:54:31 -0700, PW
<pa********@removewilliamsonenterprises.comwrote :

My approach is to close after I open, and set to nothing in the Exit
section:

sub test()
on error goto ErrHandler
dim rs as dao.recordset
if TheConditionsAreRight()
set rs=currentdb.OpenRecordset(...)
'do your thing
rs.close
end if

ExitHandler:
set rs=nothing
exit sub

Err_Handler
Msgbox Err.Description
resume ExitHandler
end sub

I guess if I really needed to, I would maintain a boolean to indicate
whether I had opened the recordset or not:
set rs=currentdb.OpenRecordset(...)
blnRsOpen = True
'do your thing

ExitHandler:
if blnRsOpen = True then rs.Close
set rs=nothing
exit sub

I agree with Lyle that it's an omission to the DAO object model that a
State property or equivalent is not available. So maintain your own.

-Tom.

>Hi,

I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset open
and a database open isn't a good idea, right?

Thanks,

-paul w
Nov 1 '06 #5
Tom van Stiphout <no*************@cox.netwrote in
news:jb********************************@4ax.com:
On Tue, 31 Oct 2006 16:54:31 -0700, PW
<pa********@removewilliamsonenterprises.comwrote :

My approach is to close after I open, and set to nothing in the Exit
section:
That has been my approach with DAO too.

I'm wondering if it is still required. Should this code which creates 100
copies of the current database and has each one open a recordset cause a
problem because it closes nothing and releases nothing?

Sub temp()
Dim db(0 To 99) As DAO.Database
Dim rs(0 To 99) As DAO.Recordset
Dim x&
For x = 0 To 99
Set db(x) = CurrentDb()
Set rs(x) = db(x).OpenRecordset("SELECT * FROM Customers")
With rs(x)
.Move 10
.Edit
.Fields("CustomerID").Value = "JONES"
End With
Next x
'Quit
End Sub

Clearly, some things are left in limbo. I've tried it or something
similar (mostly quitting with the exit button afer doing some other work)
many times over the past couple of months in Access 2003:
no ghosts
no memory problems
nada ill effect that I can observe

Did MS "fix" this?
Did they tell us?
Did I miss it?
Am I doing something wrong (not doing something I should to create a
problem)?

The Customers Table is imported from Northwind db.
Nov 1 '06 #6
On Wed, 01 Nov 2006 03:53:13 GMT, Lyle Fairfield
<ly***********@aim.comwrote:

I wish there was an authorative article from MSFT on this topic. Don't
hold your breath. If they didn't write it in the first 10 years...

In DotNet I don't write it like this because in that environment it
has clearly been stated that unclosed objects will be cleaned up.
Without such statement for DAO/COM I mostly write code like I do to
stay on the safe side.

-Tom.

>Tom van Stiphout <no*************@cox.netwrote in
news:jb********************************@4ax.com :
>On Tue, 31 Oct 2006 16:54:31 -0700, PW
<pa********@removewilliamsonenterprises.comwrot e:

My approach is to close after I open, and set to nothing in the Exit
section:

That has been my approach with DAO too.

I'm wondering if it is still required. Should this code which creates 100
copies of the current database and has each one open a recordset cause a
problem because it closes nothing and releases nothing?

Sub temp()
Dim db(0 To 99) As DAO.Database
Dim rs(0 To 99) As DAO.Recordset
Dim x&
For x = 0 To 99
Set db(x) = CurrentDb()
Set rs(x) = db(x).OpenRecordset("SELECT * FROM Customers")
With rs(x)
.Move 10
.Edit
.Fields("CustomerID").Value = "JONES"
End With
Next x
'Quit
End Sub

Clearly, some things are left in limbo. I've tried it or something
similar (mostly quitting with the exit button afer doing some other work)
many times over the past couple of months in Access 2003:
no ghosts
no memory problems
nada ill effect that I can observe

Did MS "fix" this?
Did they tell us?
Did I miss it?
Am I doing something wrong (not doing something I should to create a
problem)?

The Customers Table is imported from Northwind db.
Nov 1 '06 #7
PW
On Tue, 31 Oct 2006 16:54:31 -0700, PW
<pa********@removewilliamsonenterprises.comwrote :
>Hi,

I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset open
and a database open isn't a good idea, right?

Thanks,

-paul w

Good stuff everyone! Thanks!

-paul
Nov 1 '06 #8
Lyle Fairfield <ly***********@aim.comwrote in
news:Xn*********************************@216.221.8 1.119:
I'm wondering if it is still required. Should this code which
creates 100 copies of the current database and has each one open a
recordset cause a problem because it closes nothing and releases
nothing?

Sub temp()
Dim db(0 To 99) As DAO.Database
Dim rs(0 To 99) As DAO.Recordset
Dim x&
For x = 0 To 99
Set db(x) = CurrentDb()
Set rs(x) = db(x).OpenRecordset("SELECT * FROM Customers")
With rs(x)
.Move 10
.Edit
.Fields("CustomerID").Value = "JONES"
End With
Next x
'Quit
End Sub
When I re-use a DAO recordset variable, I close the previous
recordset but don't set it to NOTHING, on the theory that I'm
setting it to SOMETHING ELSE, which by definition will clear
whatever's there in the variable.

I then set to NOTHING after all the recordsets have been used. My
theory is that I .Close to clear the memory used by the recordset
itself, but don't need to set to Nothing for the pointer because I'm
re-using the same variable for a different pointer.

If there's an off chance that the reference count is off because
it's not been set to Nothing, I've never had any problems with it,
and I've done it religiously in every snippet of code that re-uses a
recordset variable.

(BTW, setting a db variable to CurrentDB() 100 times in a loop is
complete nonsense; first off, you can't close it, but you also
should have it outside the loop, as it can't possibly change value
on an interation of the loop)

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Nov 1 '06 #9
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
Lyle Fairfield <ly***********@aim.comwrote in
news:Xn*********************************@216.221.8 1.119:
>I'm wondering if it is still required. Should this code which
creates 100 copies of the current database and has each one open a
recordset cause a problem because it closes nothing and releases
nothing?

Sub temp()
Dim db(0 To 99) As DAO.Database
Dim rs(0 To 99) As DAO.Recordset
Dim x&
For x = 0 To 99
Set db(x) = CurrentDb()
Set rs(x) = db(x).OpenRecordset("SELECT * FROM Customers")
With rs(x)
.Move 10
.Edit
.Fields("CustomerID").Value = "JONES"
End With
Next x
'Quit
End Sub
(BTW, setting a db variable to CurrentDB() 100 times in a loop is
complete nonsense; first off, you can't close it, but you also
should have it outside the loop, as it can't possibly change value
on an interation of the loop)
I'm sorry that you didn't understand the code.

--
Lyle Fairfield

from http://msdn.microsoft.com/library/de...l=/library/en-
us/dnmdac/html/data_mdacroadmap.asp

Obsolete Data Access Technologies
Obsolete technologies are technologies that have not been enhanced or
updated in several product releases and that will be excluded from future
product releases. Do not use these technologies when you write new
applications. When you modify existing applications that are written
using these technologies, consider migrating those applications to
ADO.NET.
The following components are considered obsolete:
....
Data Access Objects (DAO): DAO provides access to JET (Access) databases.
This API can be used from Microsoft Visual Basic®, Microsoft Visual C++®,
and scripting languages. It was included with Microsoft Office 2000 and
Office XP. DAO 3.6 is the final version of this technology. It will not
be available on the 64-bit Windows operating system.
.....
Nov 1 '06 #10
PW
On Tue, 31 Oct 2006 19:54:11 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
>PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.com :
>I'd like to close a recordset and set the database to nothing if a
recordset is open if an error has occured. Leaving a recordset
open and a database open isn't a good idea, right?

The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.

-pw
Nov 2 '06 #11
PW <pa********@removewilliamsonenterprises.comwrote in
news:2f********************************@4ax.com:
On Tue, 31 Oct 2006 19:54:11 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
>>PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.co m:
>>I'd like to close a recordset and set the database to nothing if
a recordset is open if an error has occured. Leaving a
recordset open and a database open isn't a good idea, right?

The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.
Well, did you close it beforehand or set it to Nothing in your code?
If so, yes, it will not work. You have to leave the cleanup to exit
routine or, yes, you'll get an error.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Nov 2 '06 #12
PW
>>>In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.

Well, did you close it beforehand or set it to Nothing in your code?
If so, yes, it will not work. You have to leave the cleanup to exit
routine or, yes, you'll get an error.
I forgot to also set it to nothing! Doh! :-)

thanks,

-pw
Nov 2 '06 #13
PW
>>>In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.

Well, did you close it beforehand or set it to Nothing in your code?
If so, yes, it will not work. You have to leave the cleanup to exit
routine or, yes, you'll get an error.
It's working David! Thanks!

-pw
Nov 3 '06 #14
PW
On Thu, 02 Nov 2006 09:36:47 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
>PW <pa********@removewilliamsonenterprises.comwrote in
news:2f********************************@4ax.com :
>On Tue, 31 Oct 2006 19:54:11 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
>>>PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.com :

I'd like to close a recordset and set the database to nothing if
a recordset is open if an error has occured. Leaving a
recordset open and a database open isn't a good idea, right?

The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If

I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.

Well, did you close it beforehand or set it to Nothing in your code?
If so, yes, it will not work. You have to leave the cleanup to exit
routine or, yes, you'll get an error.
Typical buggy Access!

On an AfterUpdate for a combobox the code goes *directly* to:

ExitTag_pw:
If Not rstPurchases_pw Is Nothing Then
rstPurchases_pw.CLOSE
Set rstPurchases_pw = Nothing
End If
If Not rstInventory_pw Is Nothing Then
rstInventory_pw.CLOSE
Set rstInventory_pw = Nothing
End If
Set dbCurr_pw = Nothing
Exit Sub

I get object required on "If Not rstInventory_pw Is Nothing" yet
rstPurchases_pw = Nothing! rstInventory_pw = Empty!!

-pw
Nov 9 '06 #15
Sounds more like your code.

Show us the declarations for those variables as it looks like you've
declared rstInventory_pw as variant.

--

Terry Kreft
"PW" <pa********@removewilliamsonenterprises.comwrote in message
news:te********************************@4ax.com...
On Thu, 02 Nov 2006 09:36:47 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:
PW <pa********@removewilliamsonenterprises.comwrote in
news:2f********************************@4ax.com:
On Tue, 31 Oct 2006 19:54:11 -0600, "David W. Fenton"
<XX*******@dfenton.com.invalidwrote:

PW <pa********@removewilliamsonenterprises.comwrote in
news:pd********************************@4ax.co m:

I'd like to close a recordset and set the database to nothing if
a recordset is open if an error has occured. Leaving a
recordset open and a database open isn't a good idea, right?

The usual method is to test if the recordset variable Is Nothing.
Since there's no way to initialize a recordset variable without it
pointing to an open recordset, this works pretty well.

In the exit routine I use this:

If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
I tried that David and received error 3420 "Object invalid or no
longer set". The recordset was already closed before the error
occurred.
Well, did you close it beforehand or set it to Nothing in your code?
If so, yes, it will not work. You have to leave the cleanup to exit
routine or, yes, you'll get an error.

Typical buggy Access!

On an AfterUpdate for a combobox the code goes *directly* to:

ExitTag_pw:
If Not rstPurchases_pw Is Nothing Then
rstPurchases_pw.CLOSE
Set rstPurchases_pw = Nothing
End If
If Not rstInventory_pw Is Nothing Then
rstInventory_pw.CLOSE
Set rstInventory_pw = Nothing
End If
Set dbCurr_pw = Nothing
Exit Sub

I get object required on "If Not rstInventory_pw Is Nothing" yet
rstPurchases_pw = Nothing! rstInventory_pw = Empty!!

-pw

Nov 9 '06 #16
PW
On Thu, 9 Nov 2006 19:49:10 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
>Sounds more like your code.

Show us the declarations for those variables as it looks like you've
declared rstInventory_pw as variant.
Option Compare Database
Option Explicit
..
..
..

Private Sub cboItemNo_pw_AfterUpdate()

On Error GoTo ErrorTag_pw

If blnInEditMode_pw And Not blnAlreadyAdjusted_pw Then

Never makes it here (only in edit mode)
..
..
..

End If

With Me
.Requery
.txtPrice_pw = Me.cboItemNo_pw.Column(2)
.txtDesc_pw = Me.cboItemNo_pw.Column(1)
.txtQuantity_pw = 0
.txtQuantity_pw.SetFocus
End With

ExitTag_pw:
If Not rstPurchases_pw Is Nothing Then
rstPurchases_pw.CLOSE
Set rstPurchases_pw = Nothing
End If
If Not rstInventory_pw Is Nothing Then
rstInventory_pw.CLOSE
Set rstInventory_pw = Nothing
End If
Set dbCurr_pw = Nothing
Exit Sub

ErrorTag_pw:
MsgBox "Error #" & Err.number & ": " & Err.description
Resume ExitTag_pw

End Sub
I get object required on "If Not rstInventory_pw Is Nothing" yet
rstPurchases_pw = Nothing! rstInventory_pw = Empty!!

-pw
Nov 10 '06 #17
That isn't the declaration for the variables, I'm expecting to see

Dim rstInventory_pw as ...
or
Private rstInventory_pw as ...
or
Public rstInventory_pw as ...
or
Global rstInventory_pw as ...
or even
Dim rstInventory_pw
It's the bit represented by ... in the lines above which is really
important.

--

Terry Kreft
"PW" <pa********@removewilliamsonenterprises.comwrote in message
news:dt********************************@4ax.com...
On Thu, 9 Nov 2006 19:49:10 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
Sounds more like your code.

Show us the declarations for those variables as it looks like you've
declared rstInventory_pw as variant.

Option Compare Database
Option Explicit
.
.
.

Private Sub cboItemNo_pw_AfterUpdate()

On Error GoTo ErrorTag_pw

If blnInEditMode_pw And Not blnAlreadyAdjusted_pw Then

Never makes it here (only in edit mode)
.
.
.

End If

With Me
.Requery
.txtPrice_pw = Me.cboItemNo_pw.Column(2)
.txtDesc_pw = Me.cboItemNo_pw.Column(1)
.txtQuantity_pw = 0
.txtQuantity_pw.SetFocus
End With

ExitTag_pw:
If Not rstPurchases_pw Is Nothing Then
rstPurchases_pw.CLOSE
Set rstPurchases_pw = Nothing
End If
If Not rstInventory_pw Is Nothing Then
rstInventory_pw.CLOSE
Set rstInventory_pw = Nothing
End If
Set dbCurr_pw = Nothing
Exit Sub

ErrorTag_pw:
MsgBox "Error #" & Err.number & ": " & Err.description
Resume ExitTag_pw

End Sub
I get object required on "If Not rstInventory_pw Is Nothing" yet
rstPurchases_pw = Nothing! rstInventory_pw = Empty!!

-pw

Nov 10 '06 #18
PW wrote:
Typical buggy Access!
You mean typical person who blames the tools, doesn't know what he's
doing and then goes around telling people as though he's an expert that
"<such and such a platformis pretty buggy!"

Access VBA is actually pretty robust and very easy to work with.
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Be Careful, Big Bird!" - Ditto "TIM-MAY!!" - Me
Nov 10 '06 #19
PW
On Fri, 10 Nov 2006 12:30:17 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
>That isn't the declaration for the variables, I'm expecting to see

Dim rstInventory_pw as ...
or
Private rstInventory_pw as ...
or
Public rstInventory_pw as ...
or
Global rstInventory_pw as ...
or even
Dim rstInventory_pw
It's the bit represented by ... in the lines above which is really
important.
Oops!

Here ya go:

Dim dbCurr_pw As Database
Dim rstInventory_pw, rstPurchases_pw As Recordset
Dim strFind_pw As String
Dim intPurchaseID_pw As Integer

Set dbCurr_pw = CurrentDb
Nov 14 '06 #20

Ahh, good, I expected something like that.

The line ...
Dim rstInventory_pw, rstPurchases_pw As Recordset

isn't doing what you think (this is a very common mistake BTW). This
actually declares rstInventory_pw as a Variant not a Recordset.

You should replace this line with either
Dim rstInventory_pw As Recordset, rstPurchases_pw As Recordset

or (preferably in my opinion)
Dim rstInventory_pw As Recordset
Dim rstPurchases_pw As Recordset
Personally, I prefer to declare one variable per line as this makes it
easier to spot errors like this.
--

Terry Kreft
"PW" <pa********@removewilliamsonenterprises.comwrote in message
news:ue********************************@4ax.com...
On Fri, 10 Nov 2006 12:30:17 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
That isn't the declaration for the variables, I'm expecting to see

Dim rstInventory_pw as ...
or
Private rstInventory_pw as ...
or
Public rstInventory_pw as ...
or
Global rstInventory_pw as ...
or even
Dim rstInventory_pw
It's the bit represented by ... in the lines above which is really
important.

Oops!

Here ya go:

Dim dbCurr_pw As Database
Dim rstInventory_pw, rstPurchases_pw As Recordset
Dim strFind_pw As String
Dim intPurchaseID_pw As Integer

Set dbCurr_pw = CurrentDb

Nov 14 '06 #21
PW
On Tue, 14 Nov 2006 20:01:54 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
>
Ahh, good, I expected something like that.

The line ...
Dim rstInventory_pw, rstPurchases_pw As Recordset

isn't doing what you think (this is a very common mistake BTW). This
actually declares rstInventory_pw as a Variant not a Recordset.

You should replace this line with either
Dim rstInventory_pw As Recordset, rstPurchases_pw As Recordset

or (preferably in my opinion)
Dim rstInventory_pw As Recordset
Dim rstPurchases_pw As Recordset
Personally, I prefer to declare one variable per line as this makes it
easier to spot errors like this.
Well Terry, I have to admit that I messed up there. You are absolutely
correct! I knew better than that at one point in time :-)!

Thank you so much!

-paul
Nov 15 '06 #22
That would have been when you were a teenager; to quote the sign in a timber
merchants I used to use:-
"Employ a teenager, quick, while they still know it all!"

--

Terry Kreft
"PW" <pa********@removewilliamsonenterprises.comwrote in message
news:bg********************************@4ax.com...
On Tue, 14 Nov 2006 20:01:54 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
<SNIP>
Well Terry, I have to admit that I messed up there. You are absolutely
correct! I knew better than that at one point in time :-)!

Thank you so much!

-paul

Nov 15 '06 #23
PW
On Wed, 15 Nov 2006 20:03:04 -0000, "Terry Kreft"
<te*********@mps.co.ukwrote:
>That would have been when you were a teenager; to quote the sign in a timber
merchants I used to use:-
"Employ a teenager, quick, while they still know it all!"
:-)

-pw
Nov 16 '06 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Robert Mark Bram | last post by:
Hi All! My ASP page below receives the following error: Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E10) Too few parameters. Expected 2. /polyprint/test.asp, line 31 ...
4
by: Nuno | last post by:
Is there any SQL Error? Or I have to use Select case in VB code to control SQL instead. Thank you for any ans. Nuno
1
by: Ryan Hubbard | last post by:
I would like to get the list of open windows using VBA in access. Is there a collection which holds these? I know the Forms colletion hold open forms but what about Query window results? Is...
2
by: Paul T. Rong | last post by:
Who can tell me how to write vba, if I want to open the last record of "order" form where the customer name is Larry King, in other words, records with the customer name "Larry King" are many, but...
3
by: Glenn Davy | last post by:
Q. How can I 'see' the number of table id's access is using for tracking recordsets? Details: I have some ado code that itterates through a recordset and calls a procedure on each record. This...
4
by: jojo1 | last post by:
Hi: What method in VBA can be used to move through a recordset (table) then read every single field/row and then update it depending on the value? Thanks.
2
by: MLH | last post by:
I use the following in A97 to tell if a form is open: If IsNull(TheForm) Then Exit Function IsFormOpen = SysCmd(acSysCmdGetObjectState, acForm, TheForm) Is there a way I can tell if it is open...
10
by: Rob | last post by:
Hi Remember back in VBA, you could easily create a recordset, loop thru the rows, and store the values of the columns to variables... I am not even talking about writing back to the data... ...
0
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
2
by: AustinK | last post by:
I have a query with data from several tables. I open it as a recordset in a VBA module and can get data from some of the fields with eg SomeData = TheQuery!SomeField but for other fields when the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.