473,399 Members | 2,858 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.

run-time error 3061 too few parameters expected 1 Set rs = db.OpenRecordset

I cant run this. please help! the error is

run-time error 3061 too few parameters expected 1

in this line --------->> Set rs = db.OpenRecordset <---- below


Expand|Select|Wrap|Line Numbers
  1. Public Function SendEmailAdvice() As String
  2.  
  3. Dim db As DAO.Database, rs As DAO.Recordset
  4. Dim sSQL As String
  5.  
  6.    'Set environment
  7.    Set db = CurrentDb
  8.    DoCmd.SetWarnings False
  9.  
  10.    'Open the controlling recordset
  11.    Set rs = db.OpenRecordset("qrySendEmailAdvice")
  12.    While Not rs.EOF
  13.  
  14.        'For each record (Booking) send an email
  15.       'For each record (Booking) send an email
  16.  
  17.  
  18.        DoCmd.SendObject acSendNoObject, , , rs![Emails], "steveo@lifetimebrands.com; larryo@lifetimebrands.com; richo@lifetimebrands.com; baruc.estrada@lifetimebrands.com", , "Service Reminder " & rs![Type] & " # " & rs![Truck_ID], "Service for " & rs![Type] & " # " & rs![Truck_ID] & "  has been scheduled for " & rs![Day] & " " & rs![Scheduled Date] & Chr$(13) & Chr$(13) & _
  19.        "This is a reminder." & Chr$(13) & Chr$(13) & _
  20.        "If you cannot send the truck down for service please let us know before 12 noon today."
  21.  
  22.  
  23.        'Update the SM table so that emails are not duplicated
  24.        sSQL = "UPDATE SM and PM Monthly Schedule SET EmailSent=-1 WHERE ID=" & rs![ID]
  25.  
  26.  
  27.        'Cycle on to the next record
  28.        rs.MoveNext
  29.    Wend
  30.    rs.Close
  31.    Set rs = Nothing
  32.    'Control recordset now closed
  33.  
  34.    'Reset environment
  35.    DoCmd.SetWarnings True
  36.  
  37. End Function
Nov 7 '13 #1
2 3000
Seth Schrock
2,965 Expert 2GB
Please use the [CODE/] tags around your code so that it is easier to view.

It is telling you that your query qrySendEmailAdvice is requesting a parameter (there is a WHERE clause in your query that needs a value passed to it). There are two options to fix this. The complexity of the your query would the the deciding factor for me as to which one to choose. You could type out your query in VBA and thus have the value entered into the query string before you try to open the recordset. However, if the query is quite large in the amount of text, then it might be simpler to just remove the WHERE clause from the query and then open the recordset and then filter the recordset in VBA. However, this wouldn't work if other objects are depending on the query to have the WHERE clause.

Also, your UPDATE query toward the end is never ran plus it would fail if it did run because the syntax is wrong.
Nov 7 '13 #2
NeoPa
32,556 Expert Mod 16PB
Some good points.

However, while the likelihood is that the parameter is required for a reference within the WHERE clause, it can actually come from anywhere in the SQL. Any reference that the SQL engine (Jet in MS Access) cannot determine is treated as an enterable parameter.

I suggest you run your query from the database window and note the prompt. That will tell you what is not recognised by SQL and what you need to fix in your query.

NB. It is never a good idea to use a QueryDef from code that you haven't already tested this way.
Nov 7 '13 #3

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

Similar topics

8
by: Tahir Hashmi | last post by:
Consider this piece of code: #include <iostream> using namespace std; class y { public: void draw()
3
by: colm | last post by:
i get the above runtime error on the following line of code when i try to update a reord in my form when it gets to the line Set rs = DBEngine(0)(0).OpenRecordset(strSql) the entire code...
2
by: fanfromfla | last post by:
I am using a database that has worked for many years for a holiday project for needy families. My organization recently upgraded its server and changed everyone to Windows XP. I just mention that...
4
by: Richard Hollenbeck | last post by:
I thought I was very specific in this SQL request. There is a form open with a selected record (and a corresponding "lngRecipeID" on that form. The table also has a field called "lngRecipeID". ...
4
by: JH001A | last post by:
ACCESS 2003 VBA in the code below set.rs3, gets the error when I try using a parm for input to the where clause. If I use a number like the one comented out it works. Thanks for your help. ...
10
RMWChaos
by: RMWChaos | last post by:
WinVista/IE7 I am getting some weird errors only in IE7, but not in FF2.0.0.8 or NN9. It even happens on this website when I click "Sign In". The error is: "A Runtime Error has occurred."...
1
by: istya | last post by:
I am having a dumb day to day. Can anyone have a schufty at my code and see why I am getting the runtime error 3061? I'm working on 2000 if that helps at all. Dim dbs As DAO.Database Dim...
3
by: phill86 | last post by:
Hi, I am trying to run the following query in a recordset and i get the following error message Runtime error 3061 - Too few parameters. Expected 1 i am using the following code
4
by: shalskedar | last post by:
In my DB(Ms Access 2003)I want to delete a record from 1 table which is linked to another table. For ex- There are 2 tables "MasterType" which is the Master table & another table as "Sash DO"...
8
by: Viv Jones | last post by:
Hi I am trying to update a recordset, however, I cannot get the code to run as i get Runtime Error: 3061. Too Few Parameters. Expected 1. Line 6 is highlighted when you debug. Any assistance...
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
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.