Query based in Check Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alecs0101
    New Member
    • Aug 2014
    • 4

    Query based in Check Box

    Hi,

    Noob alert!!!

    Consider you have a table and one of the columns is a date, but not records have it depending on their status.
    Date is filled in only at a certain step....

    Now consider you would wish to create a query that would show either only records that have the date filled in or all values (regardless if date is there or not).

    I would presume the easiest way would be to use form and a check box to determine the user's whims, if he wants only with date (checked) or all records (unchecked).

    Created the query, the form, the check-box and the button.
    I'm stuck at the point where I have to link the check-box to the query criteria.

    Thanks
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    alecs101,

    Again, it depends on how you want to do this, as there are many ways. However, it really depends on how you are going to use the data. It this going to create a separate report in which having a standalone query might be useful? Or are you merely goingt o filter records that are already displayed for the user.

    If you already have your form that lists ALL records, then the easiest way would be to create the query (or a filter) for your displayed records.

    In the AterUpdate property of your check box, you would have something similar to this:

    Code:
    Private Sub chkWithDate_AfterUpdate()
        Dim strFilter As String
        If Me.chkWithDate Then
            strFilter = "DateField Is Not Null"
            Me.Form.Filter = strFilter
            Me.Form.FilterOn = True
        Else
            Me.Form.FilterOn = False
        End If
    End Sub
    But, please, please, PLEASE!!! do not name your date field "Date" as this is a reserved word in VBA and you will have many many problems if you do.....

    Hope this helps!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      FYI: Me.Form is synonymous with Me. That is to say adding .Form is entirely unnecessary in this code.

      To confirm, run the following code from the Immediate pane, ensuring first you have a form named {frmTest} :
      Code:
      ?(Form_{frmTest}.Form Is Form_{frmTest})
      You should see a result of True which indicates they are the same object.

      Comment

      Working...