Solved

MS Access Filter from a Command Prompt with Wildcard

Posted on 2010-09-08
3
389 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33626287
change this

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

with


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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

785 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