Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Access Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
Passing Parameters
Warren Lovegrove 
     
2 years ago
Hi, I'm having an issue passing a parameter into a query.
The parameter is created within vba and sent into the query, however query not recognising it and asks for same parameter in a "Enter Parameter Value" dialog box.
Code i have is below.

    Dim StartDate As Date, EndDate As Date
    Dim Criteria as String
    Dim db As Database
    Dim Q As QueryDef
    Dim rs As Recordset

    StartDate = DateSerial(Year(Date) - 1, 4, 1)
    EndDate = DateSerial(Year(Date), 3, 31)
    Criteria = "Between #" & StartDate & "# and #" & EndDate & "#"

    Set db = CurrentDb
    Set Q = db.QueryDefs("AccountTransactionWLTQ")
    Q.Parameters("DateParameter") = Criteria
    DoCmd.OpenQuery "AccountTransactionWLTQ"

Parameter set in Criteria under DatePaid field is [DateParameter]

Warren Lovegrove OP  @Reply  
     
2 years ago

Ronald de Boer  @Reply  
      
2 years ago
Hi Warren,

As the parameter is coming from some VBA code I assume the VBA code is in a form you need to say in your query criteria [Forms]![FormName]![DateParameter]

Ron de Boer
Warren Lovegrove OP  @Reply  
     
2 years ago
Thanks Ron, I've tried your suggestion however end up getting a run-time error 3265, Item not found in this collection.
Warren Lovegrove OP  @Reply  
     
2 years ago
I have tried separating out the DateParameter into 2 separate parameters (i.e. StartDate and EndDate), however get same issue.
I neglected to mention earlier that the query "AccountTransactionWLTQ" is being used by a crosstab query.  I have however declared both parameters within the crosstab query also as outlined within Expert level 18.
Ronald de Boer  @Reply  
      
2 years ago
Hi Warren,
Error 3265 suggests that the query is not recognising ParameterDate as specified in your VBA Code. In your Query Criteria in the Query above try:

BETWEEN [Forms]![FormName]![StartDate] AND [Forms]![FormName]![EndDate]

Ron
Richard Rost  @Reply  
          
2 years ago
Ron's suggestion should work. Put that right into your query and you don't need all the QueryDefs stuff.
Richard Rost  @Reply  
          
2 years ago
Warren Lovegrove OP  @Reply  
     
2 years ago
Thanks Ron and Richard, problem resolved, and a lot simpler solution.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Access Forum.
 

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:14:03 AM. PLT: 1s