Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime type field causes "Invalid group condition" error

Status
Not open for further replies.

Stephan888

Programmer
Aug 24, 2003
4
US
To all Crystal experts,

We've built a VB6 app which allows the user to control parameter entry, selection, grouping and sorting criteria for .rpt files from a flexible and powerful GUI.

Everything's working beautifully except for one thing: grouping on a datetime field causes an "invalid group condition" error with the GroupCondition property, and I'm pulling my hair out (what's left of it, that is) trying to solve this.

I did find this article -- -- on the Crystal KB website. It says to use the crGCDaily value instead of crGCAnyValue for date fields. Okay, so this is what I did in my VB grouping code:

'*** BEGIN CODE SNIPPET ***
With g_CRXrpt

'... more code here ...

'*** GROUP FIELD
'(Note: For our reports, grouping is based on formula fields
'like Group1, Group2, etc. instead of database fields.)
'Change grouping formula here to appropriate {table.field}
'value.
.FormulaFields.GetItemByName("Group" & CStr(m)).Text = _
"CStr({" & strRptTblName & "." & strFieldNameNoAlias & "})"

'*** GROUP CONDITION
'If field type is date use crCGDaily, otherwise use
'crGCAnyValue.
'*** ERROR always happen here with date-type field
'*** even when setting GroupCondition to crGCDaily!
If strFieldType <> &quot;Date&quot; Then
.Areas(&quot;GH&quot; & CStr(m)).GroupCondition = crGCAnyValue
Else
.Areas(&quot;GH&quot; & CStr(m)).GroupCondition = crGCDaily
End If

'*** GROUP SORT DIRECTION
If UCase(cboGroupDirection(n - 1)) = &quot;ASC&quot; Then
.Areas(&quot;GH&quot; & CStr(m)).SortDirection = crAscendingOrder
Else
.Areas(&quot;GH&quot; & CStr(m)).SortDirection = crDescendingOrder
End If

'... more code here ...
End With
'*** END CODE SNIPPET ***

In any event, I'm at my wits end. I can't tell what else I'm doing wrong and I can't find any more information on this error on the Crystal site or anywhere else. If any of you Crystal experts have experienced this error with the GroupCondition or can shed some light on the matter, I'd greatly appreciate it.

Thanks in advance,

--Stephan
 
How is strFieldType set?

Check the value of it, perhaps it's being set to DATETIME, not DATE, so the 1st condition is met.

-k
 
To all,

My programming partner did solve this, and I've received inquiries from other people out there who are experiencing the same Crystal programming error, so as a public service, I'm posting our solution below.

BTW, to SynapseVampire, thanks for getting back to me with your suggestion, but as I mentioned, we did manage to come up with the solution. Thanks again, just the same.

Regards,

--Stephan

'*** BEGIN CODE SNIPPET ***
With g_CRXrpt

'... more code here ...

'*** GROUP FIELD
'*** No need to specify GroupConditionField based on database field (WRONG!!!)
'*** This will ALWAYS be a formula field like Group1, Group2, etc.
'****** EXCEPT: Crystal won't let you change the .GroupCondition unless it
'****** FIRST knows the GroupConditionField and this has to be based on a database field!!!
.Areas(&quot;GH&quot; & CStr(m)).GroupConditionField = _
.Database.Tables(1).Fields.GetItemByName(strGrpSrtFieldName)

'*** GROUP CONDITION
If strFieldType <> &quot;Date&quot; Then
.Areas(&quot;GH&quot; & CStr(m)).GroupCondition = crGCAnyValue
Else
.Areas(&quot;GH&quot; & CStr(m)).GroupCondition = crGCDaily
End If

'*** GROUP SORT DIRECTION
If UCase(cboGroupDirection(n - 1)) = &quot;ASC&quot; Then
.Areas(&quot;GH&quot; & CStr(m)).SortDirection = crAscendingOrder
Else
.Areas(&quot;GH&quot; & CStr(m)).SortDirection = crDescendingOrder
End If

'*** Another stupid Crystal trick: SET GROUP FIELD AGAIN,
'this time based on the appropriate formula field
.Areas(&quot;GH&quot; & CStr(m)).GroupConditionField = _
.FormulaFields.GetItemByName(&quot;Group&quot; & CStr(m))
'CStr (or ToText) necessary here to prevent &quot;A number is required here&quot;
'Crystal error if field type is a number.
.FormulaFields.GetItemByName(&quot;Group&quot; & CStr(m)).Text = _
&quot;CStr({&quot; & strRptTblName & &quot;.&quot; & strGrpSrtFieldName & &quot;})&quot;

'... more code here ...

End With
'*** END CODE SNIPPET ***
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top