Solved

MS Access Filter from a Command Prompt with Wildcard

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

16 Experts available now in Live!

Get 1:1 Help Now