Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Too Few Parameters    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Too Few Parameters
Rusty Abernathy 
     
2 years ago
I have the following sql query that is used in a record set. I know that the problem is getting to the value in the MainMenuF Form, However, I cannot seem to overcome this. Any Suggestions? BTW, the query works perfect if it is used as a record source in the report but I get all records in one file and I need them separate so I can email each page(Report) to a different address.
DetailssqlString = "SELECT StudentsT.*" & _
     " FROM StudentsT INNER JOIN GradeDateT ON StudentsT.StudentID = GradeDateT.StudentID" & _
     " WHERE GradeDateT.[Grade Level] = '1st Grade'" & _
     " AND  IIF(Year(DMax('SchoolStart', 'SchoolDatesT')) = Year(Forms!MainMenuF!SchoolYearStart)," & _
     " (GradeDateT.SchoolYearStart = Forms!MainMenuF!SchoolYearStart AND StudentsT.ActiveStudent = True)," & _
     " (GradeDateT.SchoolYearStart = Forms!MainMenuF!SchoolYearStart))" & _
     " ORDER BY StudentsT.[Last Name], StudentsT.[First Name];"
    
    Set rs = CurrentDb.OpenRecordset(sqlString)
Alex Hedley  @Reply  
           
2 years ago
Is your MainMenuF open?
Alex Hedley  @Reply  
           
2 years ago
Rusty Abernathy OP  @Reply  
     
2 years ago
Yes the form is open. The problem is the referenced parameter in a recordset. Richard talks about it but I already have an extensive sql statement and I do not know how to add the additional reference to it.
Alex Hedley  @Reply  
           
2 years ago
So what part of the query isn't working or which bit is missing that you need to add?
Rusty Abernathy OP  @Reply  
     
2 years ago
As Richard pointed out the recordset cannot find Forms!MainMenuF!SchoolYearStart from the form and needs to be put in the sql query as a Select/Where statement. I do not know how to merge the Select statement to get the form parameter with the Select statement that I need in the query. I have verified that the problem is the inability of access to get a form value in the recordset. If I replace the location of the form variable with a constant, the routine works fine. Within the recordset the query will not get the value for Forms!MainMenuF!SchoolYearStart
Alex Hedley  @Reply  
           
2 years ago
So with a button click or a Debug.Print of Forms!MainMenuF!SchoolYearStart what value is returned?
Rusty Abernathy OP  @Reply  
     
2 years ago
Forms!MainMenuF! is equal to the start date of a specific year. Currently it = 8/14/2023 and the routine works perfectly if I do not use a recordset and put the statement in the record source of the report itself. But that gives me 1 file with all records returned in it. I need to separate each record so I can email it and that is why I am trying to adapt my query to a recordset. I guess I can always get the returned query results into an Array and then call each record to email in a for next loop.
Kevin Yip  @Reply  
     
2 years ago
All the form references should be outside the quotes.  In other words, those form values should be *literal values* when you use string concatenation to form the SQL statement.
Rusty Abernathy OP  @Reply  
     
2 years ago
That did it. Thank you very much for your help. The routine works perfectly. The only thing I had to add, after removing the quotes from the Form reference, was # before and after the date. I appreciate your help very much.
Kevin Yip  @Reply  
     
2 years ago
You're welcome.  A form reference like [Forms]![MyForm]![MyField] is seen as a parameter by the query, and parameters don't always work, such as in a domain aggregate function.  E.g.:

If you put a form reference in the criteria of DMax() like this, it won't work and will give a run-time error, because DMax() can't resolve the form reference into a value:

     DMax(("[Field1]", "Table1","[Field2]=[Forms]![Form1]![Field3]")

If you use a parameter query as the domain as shown below, it also won't work and will give an error:

     DLookup("[Field1]", "ParameterQuery1", ... )

The parameter query has to prompt the user to enter a value for the parameter, and that WON'T HAPPEN here.  DLookup() won't be able to pause, prompt the user, and continue.  It just can't work like that.

DMax(), DLookup(), DCount(), etc. can only work with data that are already available, such as literal values.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Too Few Parameters.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 4/30/2026 8:11:40 AM. PLT: 2s