Solved

filtering report based on boolean value

Posted on 2010-11-27
2
353 Views
Last Modified: 2012-05-10
Dear Experts,

I am trying to filter a report based on a field boolean value. I have a combo box on my form called cboTardy. The drop down's row source includes ("Excused";"Unexcused";"Excused & Unexecused") and is unbound. I would like to filter my report based on the combo box selection. If "Excused" is selected the report will only display records with the 'true' value (-1) in the tblStdTardyExcused field. If the user selects "Unexcused" then filter those records with a 'false' value (0) and if both "Excused & Unexcused" is select the report should ignore any tblStdTardyExcused filter (or allow either value) and tack on only the date filter.

I tried doing this (see code) but am getting an error message.

Ideas?

Thanks!
Private Sub cmdRunTardyReport_Click()
 On Error GoTo Err_cmdPrintReport_Click
    Dim iViewMode As Integer
    Dim stDocName As String
    Dim strFilter As String
 
    stDocName = "rptStudentTardy"

   
    If Not IsNull(Me![cboTardy]) Then
        If Me![cboTardy] = "Excused" Then
            strWhere = "[tblStdTardyExcused] = '" & True & "'"
        ElseIf Me![cboTardy] = "Unexcused" Then
            strWhere = "[tblStdTardyExcused] = '" & False & "'"
        Else
            strWhere = ""
    End If
        
        
        
        
    Else
        MsgBox "Please select a value from the dropdown " & vbNewLine & "box before printing this report.", vbCritical, "Value Not Selected"
      Exit Sub
    End If
    
     If IsDate(Me.txtStartDate) And IsDate(Me.txtEndDate) Then
           strWhere = strWhere & " And [tblStdTardyDate] Between #" & Me.txtStartDate & "# and #" & Me.txtEndDate & "#"
    Else
           strWhere = strWhere & "[tblStdTardyDate] = #" & Date & "#"
    End If

    
    Select Case MsgBox("Preview report before printing?", vbQuestion Or vbYesNoCancel, "Select Print Method")
        Case vbYes
          iViewMode = acViewPreview
        Case vbNo
          iViewMode = acViewNormal
        Case vbCancel
          GoTo Exit_cmdPrintReport_Click
    End Select

 
 'Close the report if already open: otherwise it won't filter properly.
    If CurrentProject.AllReports(stDocName).IsLoaded Then
        DoCmd.Close acReport, stDocName
    End If
   
   DoCmd.OpenReport stDocName, iViewMode, , strWhere
  
Exit_cmdPrintReport_Click:
    Exit Sub

Err_cmdPrintReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrintReport_Click
 
End Sub

Open in new window

screenshot1.png
0
Comment
Question by:shogun5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Bitsqueezer earned 500 total points
ID: 34222117
Hi,

the question is: Which error in which line?

If you want to use boolean values you can do it like this:

strWhere = "[tblStdTardyExcused] = True"

Open in new window


(directly without single quotes and converting the "True" into numeric values)

Cheers,

Christian
0
 

Author Comment

by:shogun5
ID: 34223923
Bitsqueezer,

Thanks!

I made the following modification and all went well!

Cheers!
Private Sub cmdRunTardyReport_Click()
 On Error GoTo Err_cmdPrintReport_Click
    Dim iViewMode As Integer
    Dim stDocName As String
    Dim strFilter As String
 
    stDocName = "rptStudentTardy"

   
    If Not IsNull(Me![cboTardy]) Then
        If Me![cboTardy] = "Excused" Then
            strWhere = "[tblStdTardyExcused] = True"
        ElseIf Me![cboTardy] = "Unexcused" Then
            strWhere = "[tblStdTardyExcused] = False"
        Else
            strWhere = "[tblStdTardyExcused] = False" & " or " & "[tblStdTardyExcused] = True"
    End If
        

    Else
        MsgBox "Please select a value from the dropdown " & vbNewLine & "box before printing this report.", vbCritical, "Value Not Selected"
      Exit Sub
    End If
    
     If IsDate(Me.txtStartDate) And IsDate(Me.txtEndDate) Then
           strWhere = strWhere & " And [tblStdTardyDate] Between #" & Me.txtStartDate & "# and #" & Me.txtEndDate & "#"
    Else
           strWhere = strWhere & "[tblStdTardyDate] = #" & Date & "#"
    End If

    
    Select Case MsgBox("Preview report before printing?", vbQuestion Or vbYesNoCancel, "Select Print Method")
        Case vbYes
          iViewMode = acViewPreview
        Case vbNo
          iViewMode = acViewNormal
        Case vbCancel
          GoTo Exit_cmdPrintReport_Click
    End Select

 
 'Close the report if already open: otherwise it won't filter properly.
    If CurrentProject.AllReports(stDocName).IsLoaded Then
        DoCmd.Close acReport, stDocName
    End If
   
   DoCmd.OpenReport stDocName, iViewMode, , strWhere
  
Exit_cmdPrintReport_Click:
    Exit Sub

Err_cmdPrintReport_Click:
    MsgBox Err.Description
    Resume Exit_cmdPrintReport_Click
 
End Sub

Open in new window

0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question