473,396 Members | 1,872 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,396 software developers and data experts.

Using SQL with Recordset

reginaldmerritt
201 100+
Ok so while we are on a roll here perhaps you could point me in the right direction on the next stage.

I'm trying to use the SQL statement to open a recordset so i can grap values from the record with a date closest today.

The code is as follows:
Expand|Select|Wrap|Line Numbers
  1. Set ChargeRatesRecordSet = CurrentDb.OpenRecordset("Select TOP 1 VolunteerDisclosureTotal, StandardDisclosureTotal, EnchancedDisclosureTotal, POVAPOCADisclosureTotal, EnhancedPOVAPOCADisclosureTotal, ISARegOnlyTotal, EnhancedISARegTOTAL, DateAsOf FROM ChargeRates WHERE [DateAsOf] <= Date ORDER BY [DateAsOf] DESC;")
I get runtime error 3061 too few parameters ????
Jan 26 '10 #1
12 2827
NeoPa
32,556 Expert Mod 16PB
This thread was split off from Open form where date is closest to today as it's a new and separate question.
Jan 26 '10 #2
NeoPa
32,556 Expert Mod 16PB
As this code is mostly not visible Reg, I had to copy it to somewhere else to view it. When I did I looked but found nothing amiss. That may be because it's laid out so haphazardly, but I doubt it (I looked quite carefully). The only thing I can think of is that one of your items is mis-spelled. There's nothing obviously wrong with the SQL, the format of which seems fine.
Jan 26 '10 #3
reginaldmerritt
201 100+
Thanks

It's a problem with the where statment i think

The code below works.

Expand|Select|Wrap|Line Numbers
  1. Set ChargeRatesRecordSet = CurrentDb.OpenRecordset("
  2. Select Top 1 DateAsOf
  3. FROM ChargeRates 
  4. ORDER BY [DateAsOf] DESC;")
But this code does not.

Expand|Select|Wrap|Line Numbers
  1. Set ChargeRatesRecordSet = CurrentDb.OpenRecordset("
  2. Select Top 1 DateAsOf
  3. FROM ChargeRates 
  4. WHERE [DateAsOf] <= Date
  5. ORDER BY [DateAsOf] DESC;")
Jan 26 '10 #4
reginaldmerritt
201 100+
Your right NeoPa the above wan't working becasue i missed of the brackets after 'Date' so the where statment should have been 'Where [DateAsOf] <= Date()'

Really i want the Where statement in the SQL used to Filter the Recordset to use a Field on the Form, but I think i have found a solution.

So the code now looks like this
Expand|Select|Wrap|Line Numbers
  1. Set ChargeRatesRecordSet = CurrentDb.OpenRecordset("
  2. Select Top 1 DateAsOf
  3. FROM ChargeRates 
  4. WHERE [DateAsOf] <= #" & Me.DateCRBSent & "#
  5. ORDER BY [DateAsOf] DESC;")
Needs testing to make sure it actaually works out but no error messages so far.
Jan 27 '10 #5
NeoPa
32,556 Expert Mod 16PB
Nice work. I couldn't ask for the problem to be illustrated more clearly :)

Unfortunately the SQL looks ok to me so I'm still somewhat at a loss.

Just try this to see if it has any effect :
Expand|Select|Wrap|Line Numbers
  1. WHERE ([DateAsOf] <= Date())
Otherwise that is really bizarre. We may have to look at a cut-down version of your database (if that doesn't work).
Jan 27 '10 #6
NeoPa
32,556 Expert Mod 16PB
@reginaldmerritt
I should have read this first really :D
@reginaldmerritt
Fundamentally correct, but for portable and reliable use not quite.

If you can get the form without the date filled in the Nulls need to be handled.

The format of a date literal in SQL doesn't always match the computer's default display (though it often does in the USA). It's certainly not reliable to rely on that. See Literal DateTimes and Their Delimiters (#) for more on this.
Jan 27 '10 #7
reginaldmerritt
201 100+
Great shout Neopa i'll make sure i put this to good use.

I make sure the value of the field with the date is check for null state first and then formated to m/d/y to be safe before being used in the SQL statement.
Jan 28 '10 #8
NeoPa
32,556 Expert Mod 16PB
Excellent. Not everybody (indeed very few) gets the importance of that the first time of telling.

You could consider using Nz() for handling Null values.
Jan 28 '10 #9
reginaldmerritt
201 100+
Usually that would be a good option, however, the sub routine needs to inform the user is the varaible is null so they can go back to a previous form to fix the error.

If there was a standard value to fill any varaibles found to be null then Nz() is defintly the function to use.

Thanks.
Jan 28 '10 #10
NeoPa
32,556 Expert Mod 16PB
True. True.

If the controls on a previous form shouldn't be Null then possibly change the form to ensure Null values are not accepted.
Jan 29 '10 #11
reginaldmerritt
201 100+
Yes indeed, that is where the checks should be made. However, i've still put in a check for an error value becuase a user never uses the program or reads all the error messages as you expect them to.
Jan 29 '10 #12
NeoPa
32,556 Expert Mod 16PB
Belt & Braces. Always wise in coding :)
Jan 29 '10 #13

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

Similar topics

5
by: Bruno Alexandre | last post by:
Hi guys, withou using SP, I want to be able to add a Parameter to the SQL Query and retrive the Recordset so I can use the Paging property under the recorset object.... how can I do this? I'm...
0
by: Channing Jones | last post by:
Hello everyone, I am trying to store data in a binary field of an SQL-Server table using ADODB. So far, I have managed to store a record but not any data in the binary field. I only get...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
1
by: JingleBEV | last post by:
Hi all, I don't seem to get this going, possibly lacking the knowledge of dao recordset. I try to fill this Datagrid with the DAO.recordset, but it keeps giving me the error 13 - datatype...
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...
2
by: 111mike | last post by:
Hello, Here's my problem. I cannot connect to mysql database using odbc string connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
9
ADezii
by: ADezii | last post by:
One question which pops up frequently here at TheScripts is: 'How do I retrieve data from a Recordset once I've created it?' One very efficient, and not that often used approach, is the GetRows()...
3
ADezii
by: ADezii | last post by:
Last Tip, we demonstrated the technique for retrieving data from a DAO Recordset, and placing it into a 2-dimensional Array using the GetRows() Method. This week, we will cover the same exact Method...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...
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.