• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 428
  • Last Modified:

MS Access Filter from a Command Prompt with Wildcard

I have an Access 2003 database.  In this database I have a form with a command button I'm trying to code with a filter in the prompt.

Dim stDocName As String
  Dim stLinkCriteria As String
  Dim strFindID As String
  Dim AssignedTo As String
   strFindID = InputBox("Enter Country (or leave blank for all)")
      If strFindID = "" Then
        stDocName = "frmTicOpenAsgn"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
          Else
        AssignedTo = strFindID
        stLinkCriteria = "[AssignedTo]=" & "'" & strFindID & "'"
        stDocName = "frmTicOpenAsgn"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
      End If
        DoCmd.Maximize


I want to change the strFindID to the following but I can't figure out how to get it to work.

Like "*" & [Enter Country (or leave blank for all)] & "*"

Any ideas?

Thank you so much!
0
Senniger1
Asked:
Senniger1
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:
change this

 stLinkCriteria = "[AssignedTo]=" & "'" & strFindID & "'"

with


 stLinkCriteria = "[AssignedTo] like '*" & strFindID & "*'"
0
 
Rey Obrero (Capricorn1)Commented:

altering your codes to get all when nothing is entered in the input box



Dim stDocName As String
  Dim stLinkCriteria As String
  Dim strFindID As String
  Dim AssignedTo As String
   strFindID = InputBox("Enter Country (or leave blank for all)")
      If strFindID = "" Then
        stDocName = "frmTicOpenAsgn"
        stLinkCriteria = "[AssignedTo] like '*'"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
          Else
        AssignedTo = strFindID
         stLinkCriteria = "[AssignedTo] like '*" & strFindID & "*'"
        stDocName = "frmTicOpenAsgn"
        DoCmd.OpenForm stDocName, , , stLinkCriteria
      End If

Open in new window

0
 
Senniger1Author Commented:
Absolutely what I needed.

Many thanks!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now