swell
Member
- Local time
- Today, 12:26
- Joined
- Mar 10, 2020
- Messages
- 77
Based on the information following, is there some way to select the date range?
This procedure works in other reports that do not use a cross tab query.
I am trying to generate a report based on a cross tab query, select a date range of the field [Date of Activity}
SQL from Xtab query
Originally I got this error message,
The Microsoft Access database engine does not recognize '[Date of Activity]' as a valid field name or expression.
After reviewing comments in the forum on this subject I modified the Xtab query and included parameters.
I now get this error message
In the debug Immediate window I have these following lines
This text in strWhere at the time of the error
([Date of Activity] >= #01/01/2020#) AND ([Date of Activity] < #12/31/2020#)
And this is the error message
The Microsoft Access database engine does not recognize '' as a valid field name or expression.
The module where the report is generated. This works with a non Xtab query
I don't understand where the (looks to me like two) single quotes come from. (probably a null)
Can someone point me in the correct direction how to correct the error, or achieve what I am trying to do.
This procedure works in other reports that do not use a cross tab query.
I am trying to generate a report based on a cross tab query, select a date range of the field [Date of Activity}
SQL from Xtab query
Code:
PARAMETERS [forms]![frmReportAnnualDateSelection]![txtDateFrom] Text ( 255 ), [forms]![frmReportAnnualDateSelection]![txtDateTo] Text ( 255 );
TRANSFORM Sum([Member Activity].Distance) AS SumOfDistance1
SELECT [Activity Type].[Activity ID], [Member Activity].Activity, [Activity Type].ActivityDesc, Sum([Member Activity].Distance) AS SumOfDistance, Sum([Member Activity].Hours) AS SumOfHours
FROM [Activity Type] INNER JOIN [Member Activity] ON [Activity Type].[Activity ID] = [Member Activity].Activity
WHERE ((((DatePart("m",[Date of Activity])))>=[forms]![frmReportAnnualDateSelection]![txtDateFrom] And ((DatePart("m",[Date of Activity])))<=[forms]![frmReportAnnualDateSelection]![txtDateTo]))
GROUP BY [Activity Type].[Activity ID], [Member Activity].Activity, [Activity Type].ActivityDesc
ORDER BY [Activity Type].[Activity ID], [Member Activity].Activity, (DatePart("m",[Date of Activity]))
PIVOT (DatePart("m",[Date of Activity]));
Originally I got this error message,
The Microsoft Access database engine does not recognize '[Date of Activity]' as a valid field name or expression.
After reviewing comments in the forum on this subject I modified the Xtab query and included parameters.
I now get this error message
In the debug Immediate window I have these following lines
This text in strWhere at the time of the error
([Date of Activity] >= #01/01/2020#) AND ([Date of Activity] < #12/31/2020#)
And this is the error message
The Microsoft Access database engine does not recognize '' as a valid field name or expression.
The module where the report is generated. This works with a non Xtab query
Code:
Private Sub cmdDatesForAnnualKMs_Click()
Dim stDocName As String
Dim stPathName As String
Dim strDateField As String
stDocName = "rptAnnualMonthlyDistance"
stPathName = "C:\LogBook App\LogBook files\Reports\"
stRptName = stDocName
stRptName = Mid(stRptName, 4)
'fileName = "C:\tmp\AnnualMonthlyDistance.pdf"
filename = stPathName & stRptName & ".pdf"
'Check values are entered into Date From and Date To text boxes
If Len(Me.txtdatefrom & vbNullString) = 0 Or Len(Me.txtDateTo & vbNullString) = 0 Then
MsgBox "Please ensure that a report date range is entered into the form", _
vbInformation, "Required Data..."
Exit Sub
Else
' if so run report or cancel reques
' Build the filter string.
If IsDate(Me.txtdatefrom) Then
strDateField = "[Date of Activity]" 'Put your field name in the square brackets in these quotes.
strWhere = "(" & strDateField & " >= " & Format(Me.txtdatefrom, strcJetDate) & ")"
End If
If IsDate(Me.txtDateTo) Then
If strWhere <> vbNullString Then
strWhere = strWhere & " AND "
End If
strWhere = strWhere & "(" & strDateField & " < " & Format(Me.txtDateTo + 1, strcJetDate) & ")"
End If
' Next line is to create prepare the report ready to convert to PDF
' THIS next line gives an error
DoCmd.OpenReport stDocName, lngView, , strWhere, acHidden
DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, filename, False
DoCmd.Close acReport, stDocName, acSaveNo
End If
Exit_cmdReport_Click:
Exit Sub
I don't understand where the (looks to me like two) single quotes come from. (probably a null)
Can someone point me in the correct direction how to correct the error, or achieve what I am trying to do.
Last edited by a moderator: