[AccessD] Can't Set Filter

A.D.Tejpal adtp at touchtelindia.net
Sat Sep 17 01:03:03 CDT 2005


Rocky,

    Modified code given below, should work smoothly. Basically, there was nothing wrong with your original code. The real culprit was found to be use of =< instead of >= , while building up second part of filter string.

    Some interesting features relevant to programmatic manipulation of filtering on forms are mentioned below.
    (a) Order of placement of Me.FilterOn statement with respect to Me.Filter statement does not matter.
    (b) Whenever statement Me.Filter = "" is used, FilterOn property of the form gets automatically set to False.
    (c) You don't have to use Me.Requery explicitly. It is redundant. Application of any fresh filter condition, takes care of requery as well.

    Last block of your existing code has been simplified accordingly.

Best wishes,
A.D.Tejpal
--------------

===================================
Private Sub SetFilter()
    Dim strFilter As String
    
    strFilter = ""
    If IsDate(txtDateFilterStart) Then
        strFilter = strFilter & "fldPMScheduleStartDate >= #" & _
                                                txtDateFilterStart & "#"
    End If
    
    If IsDate(txtDateFilterEnd) Then
        If strFilter <> "" Then strFilter = strFilter & " AND "
        strFilter = strFilter & "fldPMScheduleEndDate <=  #" & _
                                                txtDateFilterEnd & "#"
    End If
    
    Me.Filter = ""
    If Len(strFilter) > 0 Then
        Me.Filter = strFilter
        Me.FilterOn = True
    End If    
End Sub
===================================

  ----- Original Message ----- 
  From: Rocky Smolin - Beach Access Software 
  To: AccessD at databaseadvisors.com 
  Sent: Saturday, September 17, 2005 03:49
  Subject: [AccessD] Can't Set Filter


  Dear List:

  Can anyone see why the following code should generate the error 2448 - you can't assign a value to this object in the line Me.Filter = strFilter?

  Private Sub SetFilter()

  Dim strFilter As String

      strFilter = ""
      If IsDate(txtDateFilterStart) Then
          strFilter = strFilter & "fldPMScheduleStartDate >= #" & txtDateFilterStart & "#"
      End If
      
      If IsDate(txtDateFilterEnd) Then
          If strFilter <> "" Then strFilter = strFilter & " AND "
          strFilter = strFilter & "fldPMScheduleEndDate =< #" & txtDateFilterEnd & "#"
      End If
      
      If strFilter = "" Then
          Me.Filter = ""
          Me.FilterOn = False
      Else
          Me.Filter = strFilter
          Me.FilterOn = True
      End If
      
      Me.Requery
      
  End Sub


  MTIA,

  Rocky



More information about the AccessD mailing list