Link to home
Start Free TrialLog in
Avatar of ssblue
ssblueFlag for United States of America

asked on

Variable for crosstab query

Access:
Need my query to ask for input. I would like for this to pop open a box where I can input a variable for tbl_Tasks.New_Crafts.

TRANSFORM Count(tbl_Tasks.New_Crafts) AS CountOfNew_Crafts
SELECT tbl_Tasks.TASKSDescriptionCorrection, tbl_Tasks.TaskCombo, Count(tbl_Tasks.TaskCombo) AS CountOfTaskCombo
FROM tbl_Tasks
WHERE (((tbl_Tasks.New_Crafts)="e"))
GROUP BY tbl_Tasks.TASKSDescriptionCorrection, tbl_Tasks.TaskCombo
PIVOT tbl_Tasks.New_Crafts;
Avatar of Paul Cook-Giles
Paul Cook-Giles
Flag of United States of America image

Replace "e" with [Enter New Crafts ID:]


The brackets surround a message that will be displayed to the user when the query runs.  The user will get a dialog box prompting the entry of the criteria.
User generated image
Avatar of ssblue

ASKER

I tried that but I get an error that says 'The Microsoft Access database engine does not recognize '[Enter New Crafts ID:]' as a valid field name or expression.  ?????
Avatar of ssblue

ASKER

I can put something there and the query runs but I can't get the parameter to work.
Hm.  New_Crafts is a text field, yes?  and e is one of the entries in it?  Did you leave the quotation marks in the query?  Can you post a DB containing the table and the query so we can take a look at it?
Avatar of ssblue

ASKER

New_Crafts is a text field, yes?   yes
 e is one of the entries in it?   yes
Did you leave the quotation marks in the query?  yes
Remove the quotation marks, and try again.  :)
Avatar of ssblue

ASKER

nope

see attachment
CrossTabQueryIssue.accdb
Thanks for posting the DB.  :)
You did exactly what I told you;  turns out that crosstab queries require an additional step for user prompting.
Add PARAMETERS New_Crafts Text ( 255 ); at the top of the sql text of your query:
User generated imageand you should get a prompt to enter the criteria when you run the query.

Or, to use the GUI: open the query in Design view, and in the Show/Hide section of the Design tab, click the Parameters button.
The Query Parameters window will open. Type the name of the field you want to use the criteria against, and hit tab.  The Data Type should auto populate (if it doesn't, check the spelling of the field name).
Click OK to close the Parameter window.  

Thanks;  I didn't know this about crosstab queries.  :)
Avatar of ssblue

ASKER

I tried that but it doesn't seem to be working correctly??
It's working for me, and I can enter different letters as criteria...
CrossTabQueryIssue.accdb
Avatar of ssblue

ASKER

take the 'e' out of the query and try to run it again using e in the parameter box - you will get a different return.
ASKER CERTIFIED SOLUTION
Avatar of Paul Cook-Giles
Paul Cook-Giles
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ssblue

ASKER

That's what I need. Thanks.  Question - why would the crosstab not work with a parameter in the same way?
Avatar of ssblue

ASKER

Very helpful.  Thanks for everything.
I have to confess that I don't know;  I don't use crosstab queries much.  Perhaps one of the serious Access gods could shed some light?  Gustav?  Dale?