Solved

MS Access Filter from a Command Prompt with Wildcard

Posted on 2010-09-08
3
367 Views
Last Modified: 2012-05-10
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
Comment
Question by:Senniger1
  • 2
3 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33626287
change this

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

with


 stLinkCriteria = "[AssignedTo] like '*" & strFindID & "*'"
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 33626338

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
 

Author Closing Comment

by:Senniger1
ID: 33626383
Absolutely what I needed.

Many thanks!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now