Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006
    Posts
    2

    Unanswered: error 2448 when assigning me.filter

    I have a simple form for selecting a record to display based on entered criteria.

    When I try to assign a value to the filter property, it gives me error 2448 "can't assign a value to this object". The value I am trying to assign is a string, and I can't see what I am doing wrong. Perhaps one of you can.

    The form is based on a query:

    SELECT vendor.VENDOR, tblprmain.pr_no, tblprmain.SUMMARY,vendor.VEND_NO
    FROM tblprmain INNER JOIN vendor ON tblprmain.vendor_number = vendor.VEND_NO
    ORDER BY vendor.VENDOR, tblprmain.pr_no;

    The VBA code is on the button that starts the search. Here is the code:

    Private Sub cmdSearch_Click()
    Dim strwhere As String
    Dim lnglen As Long

    On Error GoTo cmdSearch_Click_Error

    If Not IsNull(Me.vendortoselect) Then
    strwhere = strwhere & [vendortoselect] & " and "
    End If
    ' check if there is anything in the select string, and strip off
    ' the trailing " and "
    lnglen = Len(strwhere) - 5
    If lnglen <= 0 Then
    MsgBox "nothing to select"
    Else
    strwhere = Left$(strwhere, lnglen)
    Debug.Print strwhere
    Me.Filter = strwhere

    Debug.Print Me.Filter
    Me.FilterOn = True
    End If
    cmdSearch_Click_exit:
    On Error GoTo 0
    Exit Sub

    cmdSearch_Click_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure cmdSearch_Click of VBA Document Form_Form1"
    Resume cmdSearch_Click_exit

    End Sub

    It blows up on the me.filter = strwhere

  2. #2
    Join Date
    Aug 2006
    Posts
    2

    Smile

    I found the problem myself. The filter string didn't have the correct syntax.

    The code to create the string should look like this:

    If Not IsNull(Me.vendortoselect) Then
    strwhere = strwhere & "VENDOR LIKE """ & [vendortoselect] & """ And "

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •