Results 1 to 4 of 4
  1. #1
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92

    Filter Form using VBA

    Hello,



    I am adding a button to a form that should filter the work items down to the the items that are open and that are also assigned to the current user. I thought that this would be simple but I have tried several variations of the following 2 code samples but I keep getting errors, mostly Run-Time error '13': Type Mismatch. I have a feeling that I am using the wrong number of quotes and/or applying them to the wrong places but so far none of the combos I have tried has worked so I am hoping someone can point out what I am doing wrong.

    Sample 1:

    Private Sub ECAOpenItems_Click()
    Dim usr As String
    usr = Environ("UserName")
    Me.Filter = "[WIStatus] = 'Open'" And "[ECAAssigned] = '" & usr & "'"
    End Sub

    Sample 2:

    Private Sub ECAOpenItems_Click()
    Dim usr As String
    usr = Environ("UserName")
    DoCmd.ApplyFilter, "[WIStatus] = 'Open'" And "[ECAAssigned] = '" & usr & "'"
    End Sub


    Thanks

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,850

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I have a feeling that I am using the wrong number of quotes
    Yes, you have too many quotes (Before and after the AND).
    Code:
    'Open'" And "[ECAAssigned]
    Try this:
    Sample 1:
    Code:
    Private Sub ECAOpenItems_Click()
      Dim usr As String
    
      usr = Environ("UserName")
    
      Me.Filter = "[WIStatus] = 'Open' And [ECAAssigned] = '" & usr & "'"
      Me.FilterOn = TRUE    ' also need this line
    End Sub

    Never used this form, but there are too many quotes
    Sample 2:
    Code:
    Private Sub ECAOpenItems_Click()
      Dim usr As String
      usr = Environ("UserName")
      DoCmd.ApplyFilter, "[WIStatus] = 'Open' And [ECAAssigned] = '" & usr & "'"
    End Sub

  4. #4
    Xarkath is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Location
    Millcreek WA
    Posts
    92
    Thanks for the responses. Much appriciated and as usual it seems I was over thinking/complicating things. Code works perfect now.

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

Similar Threads

  1. Replies: 9
    Last Post: 02-24-2015, 11:19 AM
  2. Filter By Form and Apply Filter Buttons
    By JustLearning in forum Forms
    Replies: 13
    Last Post: 02-18-2015, 01:01 PM
  3. Replies: 5
    Last Post: 02-07-2013, 12:21 PM
  4. Replies: 1
    Last Post: 08-16-2012, 01:51 PM
  5. Replies: 28
    Last Post: 03-08-2012, 06:47 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