Results 1 to 3 of 3
  1. #1
    raffi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2014
    Location
    Inside a Sub Procedure
    Posts
    88

    Customer List Filter

    Hello im trying to use the indicated vb below in a change event of combo-box named cbofilter within a main form where there is a subform, and I am trying to filter a field called company, I believe every aspect of the code is correct, according to what field name I have at least.... but unfortunately the [Company] field is getting end of statement error. and I've uploaded the access file which I've created a sample of what I am trying to work on



    Note that. I have set the combo-box properties:
    limit to list : no
    Auto expand : no

    here's the code

    Code:
    Private Sub cboFilter_Change()
    
      If Nz(Me.cboFilter.Text) = “” Then
        Me.Form.Filter = “”
        Me.FilterOn = False
        
    
      ElseIf Me.cboFilter.ListIndex <> -1 Then
        Me.Form.Filter = “[Company] = ‘” & _
                         Replace(Me.cboFilter.Text, “‘”, “””) & “‘”
        Me.FilterOn = True
        
    
      Else
        Me.Form.Filter = “[Company] Like ‘*” & _
                         Replace(Me.cboFilter.Text, “‘”, “””) & “*'”
        Me.FilterOn = True
      End If
      
    
      Me.cboFilter.SetFocus
      Me.cboFilter.SelStart = Len(Me.cboFilter.Text)
    End Sub

    thank you in advance.
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Try just: Me.Filter =

    My Access/VBA does not like the font of the apostrophes and quote marks. They are slanted - I have noticed this to be an issue with copy/pasted code. Had to replace them.

    Why are main form and subform bound to the same data? The code is behind main form but if you want it to filter the subform, need to reference the subform. Why not use a single form?

    Probably should filter by the ID instead of company name.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    raffi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2014
    Location
    Inside a Sub Procedure
    Posts
    88
    alrigthy then, first much thx for the answer, and ill use it in one form by splitting the form and adding combobox at the header ill give it a go

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Customer Phone List Example form
    By pkstormy in forum Code Repository
    Replies: 2
    Last Post: 05-06-2017, 03:06 PM
  2. Replies: 5
    Last Post: 03-23-2014, 09:01 AM
  3. Replies: 6
    Last Post: 12-11-2013, 09:27 PM
  4. Filter Contacts based on Selected Customer
    By davecumber in forum Forms
    Replies: 7
    Last Post: 07-25-2013, 06:17 AM
  5. Customer ID from drop down list
    By darrellx in forum Forms
    Replies: 1
    Last Post: 08-21-2011, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums