473,398 Members | 2,525 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,398 software developers and data experts.

Stumped: Query Results in VBA differ from Access UI query

I have a simple SELECT query defined in code that is resulting with one record; should be ten.

When I create a query with the same SQL in the Access database window, I get the full set of ten records.

I have no compile issues. I use the two parameters as 'interactive text' rather than true parameters. I do not get the Error 3061 b.s.

Expand|Select|Wrap|Line Numbers
  1. SampQry = "SELECT LabSample.ClientID, LabSample.TcgProjectID, LabSample.TcgSdgID, LabSample.Fraction, LabSample.LabSampleID FROM LabSample "
  2. SampQry = SampQry & "WHERE (((LabSample.TcgSdgID)='" & [Forms]![SDG_BuildAnalyteList]![ActiveSDG] & "') AND ((LabSample.Fraction)='" & [Forms]![SDG_BuildAnalyteList]![PikdFrac] & "'));"
  3.  
  4. Set NewSampSet = wkbase.OpenRecordset(SampQry, dbOpenDynaset)
  5.  
This is the SQL view of the query defined in the database:

SELECT LabSample.ClientID, LabSample.TcgProjectID, LabSample.TcgSdgID, LabSample.Fraction, LabSample.LabSampleID
FROM LabSample
WHERE (((LabSample.TcgSdgID)=[Forms]![SDG_BuildAnalyteList]![ActiveSDG]) AND ((LabSample.Fraction)=[Forms]![SDG_BuildAnalyteList]![PikdFrac]));
this query gives me the 10 records I seek

In the code, right after the NewSampSet, I have a second recordset defined by a similar query string using the same "text" parameters (w/ 25 records resulting) and have no issue with that one.

I'm stumped. Any help is appreciated. HELP!! :0)
Dec 6 '11 #1
2 1200
I found the solution: (Haven't had to do this trick in a long time) After defining the recordset, I had to use the .MoveLast method to 'account' all of the records.
This may have only been necessary to get the correct .RecordCount

I found a logic error in my inside loop: I needed to .MoveFirst (reset) the pointer in my 2nd recordset. By not doing this, the 2nd pointer was at .EOF, so there was nothing available to repeat the actions of the 1st iteration of the 1st recordset.
Dec 6 '11 #2
Killer42
8,435 Expert 8TB
Yes, this has been a constant nuisance to me over the years. When you first execute the query, the record count you get back is either 0 (no matches) or 1 (something matched). The matching records are only counted as they're accessed, so if you need the count up front you need to do something like
Expand|Select|Wrap|Line Numbers
  1. With NewSampSet
  2.   If .RecordCount > 0 Then
  3.     .MoveLast
  4.     .MoveFirst
  5.   End If
  6. End With
Dec 15 '11 #3

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

Similar topics

0
by: david liu | last post by:
access 2000 query: here's what i want to do. from an asp page, perform a search on a table in access. i have used sql code in the asp page itself, but i'd rather execute a query in access. i...
14
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ----------------------------------------------------------...
3
by: William Wisnieski | last post by:
Hello Everyone, Access 2000, I have a main unbound form with a bound datasheet subform . The subform is bound to a query that returns records based on criteria in the main form. The user...
2
by: Mattyboy | last post by:
Guys I have built a database with saved queries that runs fine in Access but when I call it from the web using ASP, an exception occurs. I have tried multiple ways of testing the databases with...
1
by: Matt | last post by:
I need to email query results from Access similar to the way I do in SQL using xp_sendmail. What is the best way to accomplish this? Thanks!
7
by: Bernard D | last post by:
Hi, I'm using Access 97. I can run a query that finds a number of records, I then need to access these results to build a formatted text file containing all of the results. There will be 25...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
1
by: CJD | last post by:
Hi, I have a set of queries in access that I would like to import into excel. My problem is that there are no records are returned when the code is run, but I do get field names. This same code...
3
by: zahmbonnie | last post by:
I have created two different queries and I would like take the results from one and subtract the results from the other. I can not figure out how to write the saved query name in my new query. Saved...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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.