Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8027675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:52:55+00:00 2026-06-04T23:52:55+00:00

I am trying to run the following query in a VBA function. I keep

  • 0

I am trying to run the following query in a VBA function. I keep getting “Too few parameters. Expected 1.”

strSQL = "Parameters [Report Date] DateTime;" & vbCrLf & _
                    "SELECT SCF.code AS [Stock Code], " & vbCrLf & _
                    "SCF.desc AS [Description], " & vbCrLf & _
                    "SCF.grp AS [Product Group]," & vbCrLf & _
                    "SCF.qCurr AS [Closing Stock], " & vbCrLf & _
                    "SCF.abp AS [Avg Price], " & vbCrLf & _
                    "Sum(([Closing Stock]*[Avg Price])) AS [STOCK VALUE], " & vbCrLf & _
                    "MaxDate.tDate AS [Last Transaction Date], " & vbCrLf & _
                    "Sum(IIf(([Last Transaction Date]>[Report Date]),([Closing Stock]*[Avg Price]),0)) AS [After Report Date], " & vbCrLf & _
                    "DateDiff(""d"",[Last Transaction Date],[Report Date]) AS [Days since Last Transaction], " & vbCrLf & _
                    "[Report Date]" & vbCrLf & _
            "INTO [FinReport] " & vbCrLf & _
            "FROM SCF RIGHT JOIN MaxDate ON MaxDate.parent = SCF.this "
strSQL = strSQL & _
            "WHERE (SCF.qCurr <> 0) " & vbCrLf & _
            "GROUP BY SCF.code, " & vbCrLf & _
                        "SCF.desc, " & vbCrLf & _
                        "SCF.grp, " & vbCrLf & _
                        "SCF.qCurr, " & vbCrLf & _
                        "SCF.abp, " & vbCrLf & _
                        "MaxDate.tDate" & vbCrLf & _
            "ORDER BY MaxDate.tDate;"

Set qdf = db.CreateQueryDef("", strSQL)
qdf.Parameters("[Report Date]").Value = Form_IO_Form.ReportDate_TB.Value
qdf.Execute

I have verified that all fields (other than [Report Date] of course) exist and the query runs by itself as an access query (pop up asks for [Report Date]).

Help!

Edit 1:
As requested here is the DB file as a ZIP. It is an Access 2007 .accdb file
DB File

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:52:56+00:00Added an answer on June 4, 2026 at 11:52 pm

    Your SQL statement will trigger error #3122 from the db engine:

    You tried to execute a query that does not include the specified expression 'DateDiff("d",[Last Transaction Date],[Report Date])' as part of an aggregate function.

    That error will cause the statement to fail before the db engine even considers any parameters.

    When you build a SQL statement with VBA, it’s better to start with one the db engine will accept. Then you should also follow the sound advice from @mwolfe02 to Debug.Print strSQL … to give yourself an opportunity to examine the completed statement you’re asking the db engine to execute.

    Edit: Having examined the ACCDB file you uploaded, I still don’t understand why your query doesn’t trigger error #3122. However the query does work as a saved query and can work when you execute it from VBA code. The reason you got the complaint about “too few parameters” is that you weren’t actually executing the temporary QueryDef you created. Instead you were attempting to execute the SQL text like this:

    ' Execute created Query '
    CurrentDb.Execute strSQL, dbFailOnError
    

    If you change to this approach (as you indicated in your question), it works without error:

    qdf.Execute
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to run the following query, but am getting a sql syntax
I'm trying to run the following query in SQL*Plus but I'm getting an error.
I'm trying to run the following query, and I'm having trouble with the wildcard.
I'm trying to run the following query from phpMyAdmin (on a local WAMP server):
I'm recieving the following error on trying to run an append query in access.
I'm trying to run the following line: Directions.loadFromWaypoints((Waypoint[])waypoints.toArray(), opts); But I'm getting: 23:41:44.595 [ERROR]
I have been trying to run the following query in SPARQL explorer SELECT DISTINCT
I am trying to run the following query : SELECT A.STEPNAME, A.BRDATE BRDATE_A, B.BRDATE
I'm trying to run the following query. It was working fine until i added
I am using SQL Server 2008, and trying to run the following query in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.