View Full Version : error in my code Filter Report By Month, Quarter and Year just like the Northwind Dat
kmanotoc 10-31-2007, 06:15 PM Hi! I am using ms access '07. I want to filter my report just like the Northwind Database wherein it has a Sales Reports Dialog and you can select by category and then by sales period.
In a table, I have the ff: fields; Body No, Date of Trip, Employee, Owner, No of Trips and Total Price
I tried ff: the Sales Reports Dialog from Northwind. I made a Sales Reports Table wherein I want to categorize it by Body No, Employee and Owner. But when I select any of my 3 categories in the filter combo box there is nothing in it. and it says there is an error on my code on this part
Private Sub InitFilterItems()
Me.lstReportFilter.RowSource = DLookupStringWrapper("[Filter Row Source]", "Sales Reports", "[Group By]='" & Nz(Me.lstSalesReports) & "'")
Me.lstReportFilter = Null
End Sub
It always highlight DLookupStringWrapper. I don't know what this code means. Pls help and tell me what I'm doing wrong. Pls
pbaldy 10-31-2007, 07:31 PM DLookupStringWrapper is not a built in function, and it doesn't sound like a function that's been created in your database (or Access would not be highlighting it). What is it?
kmanotoc 10-31-2007, 11:41 PM its a code from the northwind database...
anyways..
how can i do it that when i select a certain category in my category listbox, in my filter combobox i can see the selection. ex. category is sales by employee and when i go the the filter combobox, all i see would be the employee names. and that when i select a certain employee and i click preview a report would pop-up for that certain employee....
boblarson 10-31-2007, 11:48 PM It always highlight DLookupStringWrapper. I don't know what this code means. Pls help and tell me what I'm doing wrong. Pls
What that means is that you didn't include the function in a standard module. The function DLookupStringWrapper, as Paul has mentioned is not a standard Access function. It is a custom function and you would need to include it in your project too, in order to use it:
Public Function DLookupStringWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull As String = "") As String
DLookupStringWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
End Function
kmanotoc 11-01-2007, 12:24 AM Public Function DLookupStringWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull As String = "") As String
DLookupStringWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
End Function
am i going to include the code above to my module? this is my module:
Option Compare Database
Option Explicit
Enum SalesPeriodEnum
ByMonth = 1
ByQuarter = 2
ByYear = 3
End Enum
Sub PrintReports(ReportView As AcView)
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.
' Then close the Print Sales Reports Dialog form.
Dim strReportName As String
Dim strReportFilter As String
Dim lOrderCount As Long
' Determine report filtering
If Nz(Me.lstReportFilter) <> "" Then
strReportFilter = "([SalesGroupingField] = """ & Me.lstReportFilter & """)"
End If
' Determine reporting time frame
Select Case Me.lstSalesPeriod
Case ByYear
strReportName = "Yearly Sales Report"
lOrderCount = DCountWrapper("*", "Sales Analysis", "[Year]=" & Me.cbYear)
Case ByQuarter
strReportName = "Quarterly Sales Report"
lOrderCount = DCountWrapper("*", "Sales Analysis", "[Year]=" & Me.cbYear & " AND [Quarter]=" & Me.cbQuarter)
Case ByMonth
strReportName = "Monthly Sales Report"
lOrderCount = DCountWrapper("*", "Sales Analysis", "[Year]=" & Me.cbYear & " AND [Month]=" & Me.cbMonth)
End Select
If lOrderCount > 0 Then
TempVars.Add "Group By", Me.lstSalesReports.Value
TempVars.Add "Display", DLookupStringWrapper("[Display]", "Sales Reports", "[Group By]='" & Nz(Me.lstSalesReports) & "'")
TempVars.Add "Year", Me.cbYear.Value
TempVars.Add "Quarter", Me.cbQuarter.Value
TempVars.Add "Month", Me.cbMonth.Value
eh.TryToCloseObject
DoCmd.OpenReport strReportName, ReportView, , strReportFilter, acWindowNormal
Else
MsgBoxOKOnly NoSalesInPeriod
End If
End Sub
Private Sub Form_Load()
SetSalesPeriod ByYear
InitFilterItems
End Sub
Sub SetSalesPeriod(SalesPeriod As SalesPeriodEnum)
Me.lstSalesPeriod = SalesPeriod
Me.cbQuarter.Enabled = (SalesPeriod = ByQuarter)
Me.cbMonth.Enabled = (SalesPeriod = ByMonth)
End Sub
Private Sub lstSalesPeriod_AfterUpdate()
SetSalesPeriod Me.lstSalesPeriod
End Sub
Private Sub lstSalesReports_AfterUpdate()
InitFilterItems
End Sub
Private Sub InitFilterItems()
Me.lstReportFilter.RowSource = DLookupStringWrapper("[Filter Row Source]", "Sales Reports", "[Group By]='" & Nz(Me.lstSalesReports) & "'")
Me.lstReportFilter = Null
End Sub
Private Sub cmdPreview_Click()
PrintReports acViewReport
End Sub
Private Sub cmdPrint_Click()
PrintReports acViewNormal
End Sub
Private Function GetLastDateofTrip() As Date
GetLastDateofTrip = Nz(DMaxWrapper("[Date of Trip]", "Dumptruck Trips"), Date)
End Function
i don't know how to make code or use vba... so what i did with my database is basically follow northwind database.... including its code...
boblarson 11-01-2007, 05:42 AM Public Function DLookupStringWrapper(Expr As String, Domain As String, Optional Criteria As String, Optional ValueIfNull As String = "") As String
DLookupStringWrapper = Nz(DLookupWrapper(Expr, Domain, Criteria), ValueIfNull)
End Function
am i going to include the code above to my module?
Yes, you need to include that code in a STANDARD MODULE, Not a form module.
i don't know how to make code or use vba... so what i did with my database is basically follow northwind database.... including its code...
I know you tried, but you didn't get it all. You missed the function. It may take some time, but you'll get it eventually and you'll start to understand how it all works.
|
|