473,399 Members | 3,302 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,399 software developers and data experts.

DAO Recordset Problem

I'm trying to populate a recordset with a query I have stored in Access 07. I basically copied the lines from the help file on how to do this but substituted my own info -

Expand|Select|Wrap|Line Numbers
  1. Dim dbsCurrent As DAO.Database
  2. Dim rstEmail As DAO.Recordset
  3. Dim strService As String
  4.  
  5.  
  6. Set dbsCurrent = CurrentDb
  7. Set rstEmail = dbsCurrent.OpenRecordset("qry_EmailList")
But every time I try this, I get a "too few parameters: Expected 1" error on that last line. It works perfectly fine if I put the name of a table in there, and lets me move through the recordset and print data and everything, but for some reason it doesn't work with queries.

I must just be missing something extremely obvious here, but I've been stumped for a while.
Oct 30 '09 #1
11 2095
ChipR
1,287 Expert 1GB
What happens if you use:
Expand|Select|Wrap|Line Numbers
  1. Set rstEmail = dbsCurrent.OpenRecordset("SELECT * FROM qry_EmailList") 
Reading Database.OpenRecordset Method, I think it says a query should default to open as dynaset type, but you could also try:
Expand|Select|Wrap|Line Numbers
  1. Set rstEmail = dbsCurrent.OpenRecordset("qry_EmailList", 2) 'dbOpenDynaset
If this doesn't work, then I can only guess that qry_EmailList is spelled wrong somewhere.
Oct 30 '09 #2
Didn't work, but I think I may have figured it out. The query itself has references to controls on a specific form. Edited that out, but I'm running into another problem with type mismatches that I'm assuming is related to the fact that the query is adding and subtracting a date field.

Expand|Select|Wrap|Line Numbers
  1. [DateRevised] + 1095 - Date
...works fine in Access, but I'm assuming VBA has a problem with it even if it is just pulling it from an existing query.
Oct 30 '09 #3
ChipR
1,287 Expert 1GB
I don't get an error in VBA from, for example:
Expand|Select|Wrap|Line Numbers
  1. ?#1/1/01# + #2/2/02# + 2500
  2. 12/10/2109
So I wouldn't expect that line to produce an error, even if it's not giving you a correct date. We may need a little more information. It will be helpful if you can track down the problem, since assumptions can lead us to wasting a lot of time. NeoPa wrote a nice guide on Debugging in VBA that will certainly be helpful if you don't already use it.
Oct 30 '09 #4
Whenever I hit the button to run the code, I get a type mismatch error, and when I hit debug it always highlights the last ampersand in this code -

Expand|Select|Wrap|Line Numbers
  1. 'Set rstEmail = "SELECT tbl_PolicyList.Service, tbl_PolicyList.PolicyNumber, tbl_PolicyList.Title, [DateRevised]+1095 AS TestField, [DateRevised]+1095-Date() AS DateDue, tbl_Contacts.FirstContact, tbl_Contacts.SecondContact " & _
  2.     "FROM tbl_Contacts INNER JOIN tbl_PolicyList ON tbl_Contacts.Service = tbl_PolicyList.Service " & _
  3.     "WHERE ((([DateRevised] + 1095 - Date) <= " & strWhereDate & ")) " & _
  4.     "ORDER BY [DateRevised]+1095-Date();"
I'm assuming the problem has to do with how I am adding and subtracting dates. Is just writing "+ 1095" wrong, and if so, what format would I use instead?

Will start looking through that guide.
Oct 30 '09 #5
ChipR
1,287 Expert 1GB
At first glance, I don't see why
Expand|Select|Wrap|Line Numbers
  1. ORDER BY [DateRevised] + 1095 - Date()
would result in anything different from
Expand|Select|Wrap|Line Numbers
  1. ORDER BY [DateReviesd]
As you are just adding a constant which won't be visible in the results.
Oct 30 '09 #6
ChipR
1,287 Expert 1GB
Oh, the actual problem is probably in the previous line where you compare a Date type to a String type. To tell Access you have a date, try changing that line to:
Expand|Select|Wrap|Line Numbers
  1.   "WHERE ([DateRevised] + 1095 - Date) <= #" & strWhereDate & "# " & _ 
Oct 30 '09 #7
Still didn't work.

I tried simplifying down and isolating different parts of the query, and now even this is giving me a type mismatch error -

Expand|Select|Wrap|Line Numbers
  1. Set rstEmail = "SELECT tbl_PolicyList.Service, tbl_PolicyList.ServiceChief, tbl_PolicyList.PolicyNumber, tbl_PolicyList.Title, tbl_PolicyList.DateIssued, tbl_PolicyList.DateRevised, tbl_PolicyList.PolicyReviewer FROM tbl_PolicyList ORDER BY tbl_PolicyList.Service;"
And there is no calculation going on at all in there. I tried removing the semicolon at the end and I tried getting rid of the "tbl_PolicyList." before every field and neither one worked.
Oct 30 '09 #8
ChipR
1,287 Expert 1GB
It looks like you lost part of the line. Set recordset = String does not compute.
Expand|Select|Wrap|Line Numbers
  1. Set rstEmail = dbsCurrent.OpenRecordset("SELECT...")
Oct 30 '09 #9
Ultimately got it working using this -

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT tbl_PolicyList.Service, tbl_PolicyList.PolicyNumber, tbl_PolicyList.Title, [DateRevised]+1095 AS TestField, [DateRevised]+1095-Date() AS DateDue, tbl_Contacts.FirstContact, tbl_Contacts.SecondContact " & _
  2.     "FROM tbl_Contacts INNER JOIN tbl_PolicyList ON tbl_Contacts.Service = tbl_PolicyList.Service " & _
  3.     "WHERE ([DateRevised] + 1095 - Date()) <= " & intWhereDate & " " & _
  4.     "ORDER BY [DateRevised]+1095;"
  5. Set rstEmail = dbsCurrent.OpenRecordset(strSQL)
Note I changed "strWhereDate" to "intWhereDate" because it was a number from the beginning anyway that I just mistakenly named str and never fixed.

Somewhere along the line I mistakenly deleted the dbsCurrent.OpenRecordset part and accidentally started trying to load the string straight into the recordset (see post 5) which apparently doesn't work.. There goes a good chunk of time I'll never get back.
Oct 30 '09 #10
ChipR
1,287 Expert 1GB
Glad you got it working. Things like that can be really hard to spot, so don't be too upset until you spend days looking for some little typo.
Oct 30 '09 #11
NeoPa
32,556 Expert Mod 16PB
A tip when debugging SQL strings, is to print the string itself before trying to use it. MsgBox() or Debug.Print can be used for this. I've found that one invaluable over the years. The number of times it becomes clear that what you wanted to appear in the string and to get processed by the SQL engine, is quite different from what actually ended up there, is just too many to count.

PS. I changed the thread title for you. It's important that the title bears a meaning as we have to deal with a large number of threads here and if there's nothing to say what it is other than it's a question (or even a dumb question) then it doesn't help.
Oct 31 '09 #12

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

Similar topics

0
by: gary artim | last post by:
Hi All, I have a problem using DBIx::RecordSet. I get correct results but continue to get these messages on stderr. I looked at Compat.pm and it seems to be pointing out a problem with my call...
0
by: belacyrf | last post by:
Here's the code: ------------------------------------------------------------------- accessID = request("accessID") strSQL = "SELECT * From PendingAccRequests Where AccessID = "&accessID ...
4
by: Gerry Abbott | last post by:
Hi all. I wish to call a recordset from a function. Ive tried the following approach, -------------------------------------------------------- Function PassRS() As Recordset Dim db As...
6
by: lenny | last post by:
Hi, I've been trying to use a Sub or Function in VBA to connect to a database, make a query and return the recordset that results from the query. The connection to the database and the query...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
5
by: zMisc | last post by:
Are there any tricks in updaitng a JOINed recordset? I joned to tables and when I try to change a field on the recordset and update it, I get this error: "Unknown column 'CCDE' in 'where...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
0
by: PCroser | last post by:
I have encountered a problem when querying a table. The query passed data into a recordset which should have resulted in many records but has returned EOF. After debugging the code the only...
0
by: Yarik | last post by:
Hello, Here is a sample (and very simple) code that binds an Access 2003 form to a fabricated ADO recordset: ' Create recordset... Dim rs As ADODB.Recordset: Set rs = New ADODB.Recordset '...
2
by: wallconor | last post by:
Hi, I am having a problem using Dreamweaver CS3 standard recordset paging behavior. It doesn’t seem to work when I pass parameter values from a FORM on my search page, to the recordset on my...
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...
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
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
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
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,...

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.