Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-03-30
14
Medium Priority
?
324 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

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 46

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 46

Accepted Solution

by:
aikimark earned 2000 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 46

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

927 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