Solved

Using forms as criteria with wildcards

Posted on 2004-08-04
5
484 Views
Last Modified: 2012-05-05
I am using a form to set the criteria for a form that opens from it.  the button executes the following code:

stDocName = "View_Item"
   
    stLinkCriteria = "[Equipment]=" & "'" & Me![Equipment] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

I'd like to be able to put a wildcard character in the equipment field-- in other words, use 34* and get equipment #'s 345 and 348.  right now, if i use a * or anything else i can think of it just filters out everything.  

Thanks for any help.
0
Comment
Question by:gregdachs
  • 3
5 Comments
 
LVL 26

Expert Comment

by:dannywareham
Comment Utility
I don't think that there's a simple way of doing this.

You'd have to use an if statement to check if the last character is "*", if so, treat as wildcard, if not, perform a normal search...
0
 
LVL 14

Accepted Solution

by:
JohnK813 earned 100 total points
Comment Utility
You could try changing your criteria string to

stLinkCriteria = "[Equipment] LIKE " & "'" & Me![Equipment] & "'"

That way, if a user enters 34, the criteria is "[Equipment] LIKE '34'", which should be the same as [Equiment]=34.
But, if the user enters 34*, LIKE would return 345 or 348 or even 34QWERTY

Correct me if I'm wrong here, Danny.
0
 

Author Comment

by:gregdachs
Comment Utility
Perfect.  Thank you.
0
 
LVL 26

Expert Comment

by:dannywareham
Comment Utility
I think that you're probably right - although LIKE can be a little tempremental.

You can try:

Dim sSQL as String
stDocName = "View_Item"

If right(me.equipment.value,1)="*" then
    sSQL = "[Equipment] LIKE " & "'" & Me![Equipment] & "'"
Else
    sSQL = "[Equipment]=" & "'" & Me![Equipment] & "'"
End if

    stLinkCriteria = sSQL
    DoCmd.OpenForm stDocName, , , stLinkCriteria

This says to fetch the exact value matching [equipment] unless the last character is "*", in which case look for somethiing like the entry

:-)
0
 
LVL 26

Expert Comment

by:dannywareham
Comment Utility
Oops, beat me too it...
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

728 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

11 Experts available now in Live!

Get 1:1 Help Now