UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> "too Few Parameters" Error, Access 2016    
 
   
dg_moore
post Oct 11 2019, 07:33 AM
Post#1



Posts: 335
Joined: 22-April 11



I'm getting error "Too few parameters. Expected 1" when I execute code

CODE
Dim db As DAO.Database, rst As DAO.Recordset, qry As DAO.Recordset
Set db = CurrentDb()

      If DCount("*", "qry_NoTravEmail") > 0 Then
        Set db = CurrentDb
        Set qry = db.OpenRecordset("qry_NoTravEmail")
      ...


where qry_NoTravEmail =

SELECT [tbl_Member-Trip].TripID, [tbl_Member-Trip].LastName, [tbl_Member-Trip].FirstName, [tbl_Member-Trip].TravelerEmail
FROM [tbl_Member-Trip]
WHERE ((([tbl_Member-Trip].TripID)=[Forms]![Trips]![TripID]) AND (([tbl_Member-Trip].TravelerEmail) Is Null))
ORDER BY [tbl_Member-Trip].LastName;


The code works correctly until the Set qry statement, which is where the error is triggered.

So the DCount() on the query is working right, and the query opens correctly when opened manually (there is no problem with the parameter). The error occurs only when the query is called in the code.

Any suggestions?


Go to the top of the page
 
arnelgp
post Oct 11 2019, 07:48 AM
Post#2



Posts: 1,424
Joined: 2-April 09
From: somewhere out there...


you have parameter that is referring to a form, Trips.
the form must be open in order for your code to work.

you can try using QueryDefs

set qry = db.QueryDefs("qry_NoTravEmail").OpenRecordset
This post has been edited by arnelgp: Oct 11 2019, 07:48 AM

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
dg_moore
post Oct 11 2019, 08:17 AM
Post#3



Posts: 335
Joined: 22-April 11



The form is always open when this code is executed. I tried QueryDefs but still get the same error. I also decompiled and compacted/repaired the db, likewise with no success.
Go to the top of the page
 
arnelgp
post Oct 11 2019, 08:36 AM
Post#4



Posts: 1,424
Joined: 2-April 09
From: somewhere out there...


oh, the form is open.
CODE
Dim db As DAO.Database, rst As DAO.Recordset, qry As DAO.Recordset
Dim qd As DAO.Querydef
Dim sSQL As String

Set db = CurrentDb()


If DCount("*", "qry_NoTravEmail") > 0 Then

        set qd  = db.Querydefs("qry_NoTravEmail")
        sSQL = qd.SQL
       qd.SQL = Replace(sSQL, "[Forms]![Trips]![TripID]", Forms!Trips!TripID)

        Set qry = db.OpenRecordset("qry_NoTravEmail")

        qd.SQL = sSQL
        set qd = Nothing

--------------------
Never stop learning, because life never stops teaching.
Go to the top of the page
 
theDBguy
post Oct 11 2019, 09:57 AM
Post#5


Access Wiki and Forums Moderator
Posts: 76,379
Joined: 19-June 07
From: SunnySandyEggo


Hi. You might also give Leigh's Generic Recordset a try.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    15th October 2019 - 03:50 AM