Results 1 to 9 of 9
  1. #1
    onechriswhite is offline Novice
    Windows Vista Access 2002
    Join Date
    Jul 2010
    Posts
    22

    Form's Criteria used in Crosstab

    Hi

    I'm trying to open a crosstab query from a form, using some of the form's current data as input criteria into the query.

    When I run the crosstab query without criteria from the form, it works. When I manually type specific data into the criteria of the crosstab query, it works.
    When I use references to the form's fields in the crosstab query it says, "field not recognised" or similar.

    The crosstab query has a data source that is another query. If I try to run THIS one from the form, with criteria referenced back to data on the form, it works fine.



    The form is "FRMClass" and on the "APP" button I am trying to open the crosstab query QRYPupilAchievement_Crosstab with data sourced from the form. The non-crosstab query that is the data source for the crosstab is called QRYPupilAchievement.

    I have tried putting the referenced fields in the criteria boxes of both the normal query and the crosstab - they are currently residing in the non-crosstab, I think.

    Is it just something peculiar to crosstabs? As an alternative, if I could get a form that displays the crosstab, I could use DoCmd.OpenForm with an stLinkCriteria. Can you get crosstabs displayed in a form?

    Thanks

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I don't think you can open the query "QRYPupilAchievement" without problem.

    you should not just type the object name of the form as query's criteria. The query never know what is in you form. you need to write the value of the object to the query in the runtime using some code in the form's event.

  3. #3
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    You must know where is the following code from in you form.
    Please take 2 steps:
    1 remove the criteria from your query "QRYPupilAchievement";
    2 add one line (like following in red) to you code (Please put all the red code in one line).
    then try again.

    Private Sub CMDRunAPPCrosstab_Click()
    On Error GoTo Err_CMDRunAPPCrosstab_Click
    Dim stDocName As String

    stDocName = "QRYPupilAchievement_Crosstab"
    CurrentDb.QueryDefs(stDocName).SQL = "TRANSFORM Last(Security) AS LastOfSecurity SELECT FocusDescription FROM QRYPupilAchievement WHERE TBLClass.ClassCode='" & ClassCode & "' AND TBLPupilAchievement.Level='" & BaseLevel & "' GROUP BY FocusDescription, ClassID, [Level], AttainmentTargetID, ClassID, ClassCode PIVOT [""Name""]"

    DoCmd.OpenQuery stDocName, acViewNormal, acEdit
    Exit_CMDRunAPPCrosstab_Click:
    Exit Sub
    Err_CMDRunAPPCrosstab_Click:
    MsgBox Err.Description
    Resume Exit_CMDRunAPPCrosstab_Click

    End Sub

  4. #4
    onechriswhite is offline Novice
    Windows Vista Access 2002
    Join Date
    Jul 2010
    Posts
    22
    Thanks, that worked well

    I'm still confused as to why it worked for a standard query by refderencing the form, but not for a crosstab.

    And I have no idea how to decipher your code!

    But thank you - anything that works is fine by me!

    Chris

  5. #5
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    If you don't know why, please check my first reply.

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Things in query are different from things in VBA code. query run by data server while codes run by program interpreter, they are totally two different things, this is more obvious when using other database as data source, e.g. ORACLE, query run by ORACLE server, VBA code run by Access interpreter. ORACLE no way to know what is in you Access form. That means you need to provide the data itself to a query, not the control which holding the data.


    May I mark it as solved?

  7. #7
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    This was your problem:

    Crosstab Query with a Parameter
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    onechriswhite is offline Novice
    Windows Vista Access 2002
    Join Date
    Jul 2010
    Posts
    22
    Absolutely perfect. Thanks.

    BaldyWeb is also bookmarked... there is no escape now..

  9. #9
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    LOL! Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. crosstab query criteria
    By Sharron in forum Queries
    Replies: 3
    Last Post: 12-15-2011, 04:31 AM
  2. Crosstab Criteria or Parameters
    By lukewarmbeer in forum Access
    Replies: 3
    Last Post: 08-11-2010, 09:57 AM
  3. Query criteria retrieved from a Form's listbox
    By blacksaibot in forum Programming
    Replies: 1
    Last Post: 01-29-2010, 10:38 AM
  4. using form's control as criteria in a query
    By brandonb in forum Access
    Replies: 0
    Last Post: 06-09-2009, 02:52 PM
  5. Criteria in Crosstab Query
    By wasim_sono in forum Queries
    Replies: 1
    Last Post: 12-12-2006, 05:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums