473,406 Members | 2,710 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.

Recordset object closing unexpectedly after operation

I have this following code snippet in Access 2007.

Expand|Select|Wrap|Line Numbers
  1. strTempQuery = "qry_Resource_ID_By_Name"
  2. Set dbs = CurrentDb()
  3. Set qdf = dbs.QueryDefs(strTempQuery)
  4. qdf.Parameters(0) = lstResourceProposed.Column(0, cnt)
  5. qdf.Parameters(0) = lstResourceProposed.Column(1, cnt)
  6. Set rst = qdf.OpenRecordset()
  7. If Not rst.BOF And Not rst.EOF And rst.Fields.Count = 1 Then
  8.        iProposedResourceID = rst.Fields("Resource ID")
  9. End If
  10.  
Here, "qry_Resource_ID_By_Name" is defined as
Expand|Select|Wrap|Line Numbers
  1. SELECT Resource_ID AS [Resource ID]
  2. FROM tbl_Resource_Master
  3. WHERE Resource_Last_Name+Resource_First_Name=[?];
  4.  
The problem is that
Expand|Select|Wrap|Line Numbers
  1. If Not rst.BOF And Not rst.EOF And rst.Fields.Count = 1 Then
is failing as
Expand|Select|Wrap|Line Numbers
  1. rst.BOF
and
Expand|Select|Wrap|Line Numbers
  1. rst.EOF
are ivaluated as "True". However,
Expand|Select|Wrap|Line Numbers
  1. rst.Fields(0).Name
shows "Resource ID".

I am clueless. Any help please?
Mar 20 '10 #1
3 1461
patjones
931 Expert 512MB
Hi -

The fact that rst.Fields(0).Name shows the proper name that you assigned in the SQL just means that the recordset was in fact created; it doesn't say anything about whether the recordset actually has anything in it.

The first thing I would try is very simple, and that is to use rst.MoveFirst after opening the recordset. Sometimes this step is needed in order to actually populate it before use.

The second thing I would look at is how the query is set up. It may not be generating any records. I notice, in particular, that

Expand|Select|Wrap|Line Numbers
  1. qdf.Parameters(0) = lstResourceProposed.Column(0, cnt)
  2. qdf.Parameters(0) = lstResourceProposed.Column(1, cnt)

is making an assignment to the same thing twice. Secondly, when I write parameterized SQL, I like to name the parameters explicitly, because using "?" notation doesn't always work out the way you want it to. In your case, you could do something like:

Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [prmSomeValue] datatype;
  2. SELECT Resource_ID AS [Resource ID]
  3. FROM tbl_Resource_Master
  4. WHERE Resource_Last_Name+Resource_First_Name=[prmSomeValue];

Then you would assign the parameter a value as such:

Expand|Select|Wrap|Line Numbers
  1. qdf.Parameters![prmSomeValue] = SomeOtherValue

where you set datatype in the PARAMETERS list according to whatever kind of data it is, and "SomeOtherValue" is just whatever you are trying to pass in to the query. You can do this for multiple parameters, as long as they are all listed and properly typed in the PARAMETERS clause of the SQL string.

Let me know how it works out.

Pat
Mar 20 '10 #2
Well, it's solved. And it was really stupid to do a programming mistake like this. :)

Pat, the correct code was
Expand|Select|Wrap|Line Numbers
  1. qdf.Parameters(0) = lstResourceProposed.Column(0, cnt) & lstResourceProposed.Column(1, cnt)
And this was the reason that no value was being fetched from the table, therefore, the recordset was understandably empty.

Pat, thank you for pointing out, and I will take the suggestion of naming the parameter as this will of course be a good practice as well.
Mar 20 '10 #3
patjones
931 Expert 512MB
You're welcome! Any time.
Mar 20 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: dmiller23462 | last post by:
My brain is nuked....Can anybody tell me right off the bat what is wrong with this code? Along with any glaring errors, please let me know the syntax to display a message (Response.Write would be...
5
by: Simone | last post by:
Hello I hope you guys can help me. I am very new to ADO... I am creating a ADODB connection in a module and trying to access it from a command button in a form. Function fxEIDAssgn(plngEID As...
2
by: S. van Beek | last post by:
Dear reader, I am using the following code:
18
by: Darryl Kerkeslager | last post by:
When I open an ADO Recordset, I close it. However, it seems that there may be some difference in this manner of opening a Recordset: Dim rL As ADODB.Recordset Set rL = New ADODB.Recordset ...
4
by: Zeng | last post by:
Hello, I'm wondering if anybody has seen this problem. I basically need to cycle through ~30000 db rows to update the data, I load up the id of the rows I need first, put them into ArrayList,...
0
by: Boris | last post by:
I have a service developed in Visual C++ in "mixed mode" (originally developed as unmanaged under VS 6.0, and now uses managed FCL classes). I use FCL System.Messaging.MessageQueue and...
10
by: Roger Withnell | last post by:
I'm using ASP, VBScript and SQL Server. I'm also using UTF-8 character set and so my codepage is 65001 and SQL Server datatype nvarchar. I can insert unicode characters correctly into the...
6
by: blue875 | last post by:
Hello helper people who are smarter than me: I have a form that needs to submit multiple queries to different tables during one Sub's execution. Some sections are as simple as: 1| With rst 2|...
1
by: vinodkus | last post by:
vinod...@gmail.com wrote: Please stop shouting. Total records?? I think (hope) you mean "count of the total records". In
1
by: madhupk | last post by:
this is regarding C trigger function in postgresql 8.2 The function trigf reports the number of rows in the table ttest and skips the actual operation if the command attempts to insert a null...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.