Solved

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

Posted on 2012-03-30
14
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40

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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

751 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