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

Run time error - "Too Few parameters,Exception 1"

P: 1
Expand|Select|Wrap|Line Numbers
  1. Dim cstsname As String
  2. Dim cstpc As String
  3.  
  4. Dim rstresult As Recordset 'recordset to store output
  5. Dim mydatabase As Database
  6.  
  7. 'Variable to store user entered surname
  8. Me.Text20.SetFocus
  9. cstsname = Text20.Text
  10.  
  11. 'Variable to store user entered postcode
  12. Me.Text22.SetFocus
  13. cstpc = Text22.Text
  14.  
  15. 'sql statement to select from customer table
  16.  
  17. Set mydatabase = CurrentDb
  18.  
  19. Set rstresult = mydatabase.OpenRecordset( _
  20. "SELECT CustomerID, CustomerForename, CustomerSurname, CstPostcode FROM tblcustomer WHERE CustomerSurname = '" & cstsname & "' AND CustPostcode = '" & cstpc & "'", dbOpenDynaset, dbReadOnly)
I am trying to use the select statement to retrieve the matching record from a table of customers details and output them to a list box. I keep getting "Too few parameters, Exception 1". I am using variables as can be seen from the code above and not directly referenceing objects on the Microsoft access form. Any suggestions.
Sep 25 '08 #1
Share this Question
Share on Google+
1 Reply


Expert Mod 2.5K+
P: 2,545
Hi, and Welcome to Bytes!

There are two different kinds of recordsets which can be used - ADO, which is generally more suited for applications outside of Access that need to refer to tables via the JET database engine (or via connections to client-server databases such as SQL Server), and DAO, the native Access recordset type.

Their methods have different definitions and arguments.

In Access 2003 the default type changed to the slightly different ADO from the native DAO recordsets, leading to confusing error messages like the one you have mentioned.

To resolve this change your definition of rstresult to qualify it with the DAO type:

DIM rstresult as DAO.Recordset

To use DAO recordsets you must also ensure that there is a reference to the Microsoft DAO 3.X object library in your project references. From the VB editor select Tools, References and ensure that the latest version is ticked if it is not currently ticked, otherwise you will find the compiler generates a syntax error on the qualified declaration.

-Stewart

ps the actual error message is "too few parameters, expected 1" (not exception 1)
Sep 25 '08 #2

Post your reply

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