Solved

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

Posted on 2012-03-30
14
296 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all 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

Back Up Your Microsoft Windows Server®

Back up 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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

789 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