By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

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

P: 1
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
Share this Question
Share on Google+
2 Replies


Seth Schrock
Expert 2.5K+
P: 2,941
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
Expert Mod 15k+
P: 31,494
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

Post your reply

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