I've gone almost blind reading all the different threads about this, and I just can't see my issue. Potentially stupidity, but most likely something very simple.
Setup:
I've a cross-tab query that uses a couple of regular feeder queries to build up what I want. The middle query has a parameter to limit it before it gets to the crosstab. I've declared the parameter in as many combinations as I can think of: Both the middle query and the crosstab, JUST the crosstab, and just the middle query. Either way it doesn't work when I open the report.
First query
that feeds into the middle query (query2):
and then the crosstab:
If I execute the crosstab from the design window, I get a popup for parm1, enter the 4digit year and all is good: I get what I want.
If I open up the report, I get a runtime error 3601: Too few parameters. Expected 1. on the last line of code below:
This may be making things more complex because I'm putting the column headers in dynamically as per @isladogs fantastic post (that I can't post a link to), but it's failing before I get there, so I don't think that's the case.
I guess I have a couple of questions:
Here's my Immediate Window contents when I'm stopped in debug:
Setup:
I've a cross-tab query that uses a couple of regular feeder queries to build up what I want. The middle query has a parameter to limit it before it gets to the crosstab. I've declared the parameter in as many combinations as I can think of: Both the middle query and the crosstab, JUST the crosstab, and just the middle query. Either way it doesn't work when I open the report.
First query
SQL:
SELECT Members.PKID AS shooterID, [members].[firstname] & " " & [members].[lastname] AS shooterName, MembershipType.MembershipType AS MembershipType, MembershipPayments.seasonpaid AS season, members.membertype as memberType
FROM MembershipType RIGHT JOIN (Members LEFT JOIN MembershipPayments ON Members.PKID = MembershipPayments.MemberID) ON MembershipType.PKID = Members.MemberType
UNION ALL select guests.GuestID as shooterID, guests.firstname & " " & guests.lastname as shooterName, "Guest" as MembershipType, guests.Season AS season, 4 AS memberType
from Guests;
SQL:
PARAMETERS parm1 Short;
SELECT qCS.shooterName AS shooter, Meets.MeetDate, IIf(DLookUp("memberid","attendance","memberid = " & [qCS].[shooterID] & "and meetID = " & [meets].[pkid])=[qCS].[shooterID],True,False) AS attended, qCS.membershiptype AS membershiptype
FROM Meets, qryControlSheet AS qCS
WHERE (((qCS.season)=[parm1]) AND ((Year([MeetDate]))=[season]))
SQL:
PARAMETERS parm1 Short;
TRANSFORM First(Query2.attended) AS FirstOfattended
SELECT Query2.shooter, Query2.membershiptype
FROM Query2
GROUP BY Query2.shooter, Query2.membershiptype
PIVOT Query2.MeetDate;
If I execute the crosstab from the design window, I get a popup for parm1, enter the 4digit year and all is good: I get what I want.
If I open up the report, I get a runtime error 3601: Too few parameters. Expected 1. on the last line of code below:
Code:
<snip>
seasonArg = PullOpenArgR(Me, 0)
Me.seasonLabel.Caption = seasonArg
strQuery_CT = "Query2_crosstab"
strQuery_Inner = "Query2"
strSQL = "PARAMETERS parm1 Short;" & _
" TRANSFORM First(Query2.attended) AS FirstOfattended" & _
" SELECT Query2.shooter, Query2.membershiptype" & _
" FROM Query2" & _
" GROUP BY Query2.shooter, Query2.membershiptype" & _
" PIVOT Query2.MeetDate;
Debug.Print strSQL
CurrentDb.QueryDefs(strQuery_CT).Parameters("[parm1]") = seasonArg
CurrentDb.QueryDefs(strQuery_CT).sql = strSQL
Set Rs = CurrentDb.OpenRecordset(strSQL) 'This is the error
<snip>
This may be making things more complex because I'm putting the column headers in dynamically as per @isladogs fantastic post (that I can't post a link to), but it's failing before I get there, so I don't think that's the case.
I guess I have a couple of questions:
- What stupidity am I up to? Do I need to declare the parm in both? Just in one? The one it's used or the crosstab? I've read that you've got to declare the parm in the crosstab, and it kinda makes sense to me that it gets pushed down into the middle SQL, but I'm just at a loss to figure this out.
I swear I've tried every combination going, but I'm about to go ahead and give them all a go. - If I have my crosstab query already saved, do I need to rebuild it in the code? Can't I just do the querydef parameter thing and get the SQL to open as the recordset?
Here's my Immediate Window contents when I'm stopped in debug:
Code:
PARAMETERS parm1 Short; TRANSFORM First(Query2.attended) AS FirstOfattended SELECT Query2.shooter, Query2.membershiptype FROM Query2 GROUP BY Query2.shooter, Query2.membershiptype PIVOT Query2.MeetDate;
?strsql
PARAMETERS parm1 Short; TRANSFORM First(Query2.attended) AS FirstOfattended SELECT Query2.shooter, Query2.membershiptype FROM Query2 GROUP BY Query2.shooter, Query2.membershiptype PIVOT Query2.MeetDate;
?seasonarg
2024
?Currentdb.QueryDefs(strQuery_CT).Parameters.Count
1
?CurrentDb.QueryDefs(strQuery_CT).Parameters("[parm1]").Name
parm1
?Currentdb.QueryDefs(strQuery_CT).Parameters("[parm1]").value
<blank line - no value>
Last edited: