Full Version: QueryDefs.Fields.Count not working for a particular crosstab query
UtterAccess Discussion Forums > Microsoft® Access > Access Reports
kmpirish
Hello all,

I'm writing a crosstab report that will have dynamic headers to match the headers in my crosstab query. An integral part of this, of course, is accessing the Fields property of the query def. For now, I'm just starting with a field count. For some reason, I keep getting a field count of 0. Here's my code from the report (which works with other databases/crosstab queries and in my current db if I switch the query from crosstab to select):

CODE
Private Sub Report_Open(Cancel As Integer)
    Dim db As Database, Qrydef As QueryDef, fldcount As Integer
    
    Set db = CurrentDb
    Set Qrydef = db.QueryDefs("a_TEMP")
    
    fldcount = Qrydef.Fields.Count
    MsgBox fldcount, vbOKOnly, "Field Count"

End Sub


Here is the code for my crosstab query which, of course, looks beautiful in datasheet view (it has 10 fields)...
CODE
PARAMETERS [Forms]![frmDrRptSelectionMenu]![txtDrName] IEEEDouble;
TRANSFORM Sum(qryDr_InptAdmits.NoInptAdmits) AS SumOfNoInptAdmits
SELECT qryDr_InptAdmits.DrNo
FROM qryDr_InptAdmits
GROUP BY qryDr_InptAdmits.DrNo
PIVOT qryDr_InptAdmits.MonthOfService;


Any ideas why I'm getting a field count of 0? Thanks in advance!

Kate
kmpirish
Well, I answered my own question....sort of. The reason I'm getting a field count of 0 is the parameter statement in my SQL:

PARAMETERS [Forms]![frmDrRptSelectionMenu]![txtDrName] IEEEDouble;

This is a problem because I need this crosstab query to show only records matching the [txtDrName] value. When I add [Forms]![frmDrRptSelectionMenu]![txtDrName] as a criteria to the query I get the following error:

The Microsoft Office Access database engine does not recognize '[Forms]![frmDrRptSelectionMenu]![txtDrName]' as a valid field name or expression.

I added the PARAMETERS statement to the SQL to fix that very error. So now I'm screwed either way I go. Does anyone know how I can have criteria/parameters in a crosstab query without causing errors or destroying my ability to use the QueryDefs.Fields.Count property?

Thanks,
Kate
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.