473,396 Members | 1,774 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.

Code not working when parameters added, too few parameters expected 3

I have a access query which i filter using 3 combo boxes within a form (day, location, id). I have created a function to populate a access email with email addresses form the query this worked fine until i added parameters to my query it now give the error "too few parameters expected 3 . I would really appreciate help on this. Please see code below and image of my query attached:

Expand|Select|Wrap|Line Numbers
  1. Private Sub BCCMail_Click()
  2. On Error GoTo Err_BCCMail_Click
  3.  
  4. Dim rst As DAO.Recordset
  5. Dim MyOutlook As New Outlook.Application
  6. Dim MyMail As Outlook.MailItem
  7. Dim StrBCC As String
  8. Dim stDocName As String
  9.  
  10.    stDocName = "QEmail"
  11. Set rst = CurrentDb.OpenRecordset(stDocName, dbOpenForwardOnly)
  12. With rst
  13. Do Until .EOF
  14. StrBCC = StrBCC & ![E-mail] & ";"
  15. .MoveNext
  16. Loop
  17. .Close
  18. End With
  19. StrBCC = Left(StrBCC, Len(StrBCC) - 1)
  20.  
  21. Set MyOutlook = New Outlook.Application
  22. Set MyMail = MyOutlook.CreateItem(olMailItem)
  23. MyMail.BCC = StrBCC
  24. MyMail.Display
  25.  
  26. Set MyOutlook = Nothing
  27. Set rst = Nothing
  28.  
  29. Exit_BCCMail_Click:
  30.     Exit Sub
  31.  
  32. Err_BCCMail_Click:
  33.     MsgBox Err.Description
  34.     Resume Exit_BCCMail_Click
  35.  
  36. End Sub
  37.  
Attached Images
File Type: jpg query.jpg (21.7 KB, 104 views)
Apr 8 '11 #1
1 1618
Stewart Ross
2,545 Expert Mod 2GB
Hi. Problem is that the references to form controls in your where clause can't be interpreted by VBA as field values when executed in code as above. Solution to this is to supply explicit parameters to the query using suitable code, as outlined in the DAO querydef example about half-way down the following explanatory article from MSDN:

Everything About Using Parameters from Code

You would need to replace your current OpenRecordset method in line 11 with something based on the example shown by MSDN, where the recordset is opened from a querydef in which you supply the appropriate parameter values:

Expand|Select|Wrap|Line Numbers
  1. Dim db As DAO.Database
  2. Dim qdf As DAO.QueryDef
  3. Dim rst As DAO.Recordset
  4.  
  5. Set db = CurrentDb
  6. Set qdf = db.QueryDefs(stDocName)
  7. qdf.Parameters(0) = Forms!yourformname!yourfield1
  8. qdf.Parameters(1) = Forms!yourformname!yourfield2
  9. qdf.Parameters(2) = Forms!yourformname!yourfield3
  10.  
  11. Set rst = qdf.OpenRecordset
I can't read the control names from the low definition jpeg you supply. I also cannot tell what the order of the three parameters in your query will be - you will need to find this out yourself.

-Stewart
Apr 12 '11 #2

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

Similar topics

8
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
4
by: Mike | last post by:
Hi all, I have a vb.net program running as a service that uses a network path to query a file. If System.IO.File.Exists(fpath & "\" & filename) Can anyone tell me why the above isn't working?...
3
by: jan82 | last post by:
Hi all I'm developing a website with Visual web developer in C#. Everything works fine when testing using ctrl+F5. Also, IIS runs ASP.NET pages without any problems. The problem I'm facing...
1
by: shumaila | last post by:
hello all can anybody help me???? My asp pages are not working, when i run it, it ask me for downloading?
1
by: suneel271 | last post by:
code working in internet explorer but not in mozilla and iam getting erroe like window.event has no properties and here is the code <%@ page language="java" contentType="text/html;...
3
by: kepskp | last post by:
i just write code for select option in combo box which i m select but when i press search button and then click on back button then there in no option selected. and that same code working in ie7 and...
2
by: Joe | last post by:
I'm binding to a column in a TemplateField. In some cases the join I have returns a null for an int field. I would like to specify a default value somehow so I don't end up with a null exception. ...
8
by: azegurb | last post by:
Hi i have taken news script with image upload feature it works fine. it show image and its being getting smalled thumbnail at the right side but when i added news without image instead of image...
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
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...
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.