Solved

Search field: ability to find 1 part, range, or specific parts

Posted on 2012-03-30
14
290 Views
Last Modified: 2012-03-31
Dear experts!
I am trying to find canned code that allows me to enter a search field, similar to the print dialog in Windows: ability to find one or more parts, according to any of the following syntax options:
1 (finds part 1)
1-4 (finds parts 1-4)
1,4,6,7 (finds parts 1 4 6 and 7)
etc.

Function would validate the string in some fashion, and then be able to set the filter on a subform to only those parts whose key field matched the above criteria.

Any ideas?

THANKS
0
Comment
Question by:terpsichore
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37789855
post a sample db and detail explanation...
0
 
LVL 39

Expert Comment

by:als315
ID: 37790115
You can create function with text string and criteria as parameters, which will return true or false.
Use split to separate criterias from delimited string. If any of criteria will match, return true, else - false.
Add this function as a column to your subform's record source. Add filter to this field (=true). After criteria field will be changed, requery subform. Filter can be switched on and off.
0
 

Author Comment

by:terpsichore
ID: 37790852
I guess j was asking if someone had or knew of a canned procedure since the logic isn't trivial.
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 45

Expert Comment

by:aikimark
ID: 37791063
your description is trivial.  If the problem isn't trivial, you need to be more specific.
0
 

Author Comment

by:terpsichore
ID: 37791077
I will do my best.
We have a part table, that has a key field (autonumber) of ID, and a Part_Number that is sequential within each project (1,2,3,4,5 - no other numbering is possible; these numbers are automatically assigned).
I have a subform that displays records for the various parts on this project. The problem is that many projects have many parts and the display is cumbersome.
We would like a control similar to that found in the print dialog, where you can choose to print pages like this: 1 or 1-2 or 1,3,5,7.
Hopefully that helps....
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37791129
there is no available canned codes for what you are want.. here is how you can start this going

dim str as string, j as integer, strDelim, strFilter, nArr

'test for the content of the textbox named "txt0"

if instr(txt0,"-") > 0 then strdelim="-"

if instr(txt0,",") > 0 then strdelim=","

select case strdelim
     case "-"
            strFilter="[part_number] >= " & split(txt0,"-")(0) &" and [part_number] <= " & split(txt0,"-")(1)

     case ","
            nArr=split(txt0,",")
            for j=0 to ubound(nArr)
                  str=str & "," & nArr(j)
             next
            str=mid(str,2)
            strFilter="[part_number] In (" & str & ")"

    case else
           strFilter="[part_number]= " & txt0
end select


now you can use strFilter to filter the subform



me.subformcontrolName.form.filter=strFIlter
me.subformcontrolName.form.filteron=true
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37791179
This will work to create a selection criterion for a filter property or a domain function or a query.
Public Function RecordFilter(ByVal parmFilter As String, ByVal parmKeyFieldname As String) As String
    Dim strCondition As String
    Dim strParsed() As String
    Dim strInVals As String
    Dim strBetweenVals As String
    Dim lngLoop As Long
    strParsed = Split(parmFilter, ",")
    For lngLoop = 0 To UBound(strParsed)
        If InStr(strParsed(lngLoop), "-") = 0 Then
            strInVals = strInVals & "," & strParsed(lngLoop)
        Else
            strBetweenVals = strBetweenVals & " and (" & parmKeyFieldname & " between " & Split(strParsed(lngLoop), "-")(0) & " and " & Split(strParsed(lngLoop), "-")(1) & ")"
        End If
    Next
    RecordFilter = parmKeyFieldname & " In (" & Mid(strInVals, 2) & ") " & strBetweenVals
End Function

Open in new window


This is a sample test in the immediate window.
x="1,3,5,7,13-19, 21, 26-35"
?RecordFilter(x, "id")
id In (1,3,5,7, 21)  and (id between 13 and 19) and (id between  26 and 35)

Open in new window

0
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 37791203
oops.  the logical operator should be an OR instead of an AND

Public Function RecordFilter(ByVal parmFilter As String, ByVal parmKeyFieldname As String) As String
    Dim strCondition As String
    Dim strParsed() As String
    Dim strInVals As String
    Dim strBetweenVals As String
    Dim lngLoop As Long
    strParsed = Split(parmFilter, ",")
    For lngLoop = 0 To UBound(strParsed)
        If InStr(strParsed(lngLoop), "-") = 0 Then
            strInVals = strInVals & "," & strParsed(lngLoop)
        Else
            strBetweenVals = strBetweenVals & " or (" & parmKeyFieldname & " between " & Split(strParsed(lngLoop), "-")(0) & " and " & Split(strParsed(lngLoop), "-")(1) & ")"
        End If
    Next
    RecordFilter = parmKeyFieldname & " In (" & Mid(strInVals, 2) & ") " & strBetweenVals
End Function

Open in new window


should return the following string
id In (1,3,5,7, 21)  or (id between 13 and 19) or (id between  26 and 35)

Open in new window

0
 

Author Closing Comment

by:terpsichore
ID: 37791284
amazing - perfect solution. thanks so much.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37791348
:-)
0
 

Author Comment

by:terpsichore
ID: 37791414
actually I should have awarded capricorn some points as well - my apologies. How do I notify sysadmin?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 37791555
click on  Request Attention  somewhere below the box where you posted your original question
0
 
LVL 45

Expert Comment

by:aikimark
ID: 37791860
@capricorn1

Does your code cover multiple #-# ranges?
0
 

Author Comment

by:terpsichore
ID: 37791863
yes - I tweaked the original code (there were a few modifications needed) and it is working well. thanks.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to Classify of email (pdf attachments) 7 36
Calculation in Access 5 26
SQL multicriteria from ONE textbox 32 43
SQL Group on First occurrence 9 25
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

809 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