Filter Records after FindRecord

I created a cboQuickSearch combo box, where I can choose the field I would
like to search on. The txtSearchBox text field is where I enter the search
data. I have three issues:

     1. I would like to filter the records once found. 

     2. I want to be able to enter a few characters instead of having to
enter the whole word.

     3. Is there shorter code to do the same thing?

Below is the code I created:

     Private Sub txtSearchBox_AfterUpdate()
          If Me.cboQuickSearch.Value = 1 Then ' Company ID
               Me.txtCompanyID.SetFocus
               If Not IsNull(txtSearchBox) Then
                     DoCmd.FindRecord txtSearchBox
                     Me.txtBlank.SetFocus
                     Me.txtSearchBox.Value = Null
               End If
         Else
               If Me.cboQuickSearch.Value = 2 Then ' Street Number
                     Me.txtAddressStreetNumber.SetFocus
                     If Not IsNull(txtSearchBox) Then
                          DoCmd.FindRecord txtSearchBox
                          Me.txtBlank.SetFocus
                         Me.txtSearchBox.Value = Null
                     End If
         Else
               If Me.cboQuickSearch.Value = 3 Then ' Street Name
                     Me.txtFullStreetName.SetFocus
                     If Not IsNull(txtSearchBox) Then
                           DoCmd.FindRecord txtSearchBox
                           Me.txtBlank.SetFocus
                           Me.txtSearchBox.Value = Null
                     End If
         Else
                If Me.cboQuickSearch.Value = 4 Then ' Designation
                      Me.txtAddressDesignation.SetFocus
                      If Not IsNull(txtSearchBox) Then
                           DoCmd.FindRecord txtSearchBox
                           Me.txtBlank.SetFocus
                           Me.txtSearchBox.Value = Null
                      End If
        Else
               If Me.cboQuickSearch.Value = 5 Then ' Box / PO Box
                     Me.txtAddressBoxNumber.SetFocus
                     If Not IsNull(txtSearchBox) Then
                           DoCmd.FindRecord txtSearchBox
                           Me.txtBlank.SetFocus
                           Me.txtSearchBox.Value = Null
                      End If
         Else
                If Me.cboQuickSearch.Value = 6 Then ' City
                       Me.txtAddressCity.SetFocus
                       If Not IsNull(txtSearchBox) Then
                             DoCmd.FindRecord txtSearchBox
                             Me.txtBlank.SetFocus
                             Me.txtSearchBox.Value = Null
                        End If
          Else
                 If Me.cboQuickSearch.Value = 7 Then ' State
                        Me.txtAddressState.SetFocus
                        If Not IsNull(txtSearchBox) Then
                             DoCmd.FindRecord txtSearchBox
                             Me.txtBlank.SetFocus
                             Me.txtSearchBox.Value = Null
                        End If
           Else
                 If Me.cboQuickSearch.Value = 8 Then ' Zip Code
                        Me.txtAddressPostalCode.SetFocus
                        If Not IsNull(txtSearchBox) Then
                        DoCmd.FindRecord txtSearchBox
                        Me.txtBlank.SetFocus
                        Me.txtSearchBox.Value = Null
                 End If
     End If
     End If
     End If
     End If
     End If
     End If
     End If
     End If

     End Sub

Thank you for your suggestions?

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/201006/1

0
lmcc
6/3/2010 4:24:02 AM
access.modulesdaovba 1670 articles. 0 followers. Follow

2 Replies
793 Views

Similar Articles

[PageSpeed] 27

Hello mcc.

"lmcc" wrote:
> I created a cboQuickSearch combo box, where I can choose the field I
> would like to search on. The txtSearchBox text field is where I enter
> the search data. I have three issues:
>
>     1. I would like to filter the records once found.
>
>     2. I want to be able to enter a few characters instead of having to
> enter the whole word.
>
>     3. Is there shorter code to do the same thing?
>
> Below is the code I created:
>
>     Private Sub txtSearchBox_AfterUpdate()
>          If Me.cboQuickSearch.Value = 1 Then ' Company ID
>               Me.txtCompanyID.SetFocus
>               If Not IsNull(txtSearchBox) Then
>                     DoCmd.FindRecord txtSearchBox
>                     Me.txtBlank.SetFocus
>                     Me.txtSearchBox.Value = Null
>               End If
>         Else
>               If Me.cboQuickSearch.Value = 2 Then ' Street Number
>                     Me.txtAddressStreetNumber.SetFocus
>                     If Not IsNull(txtSearchBox) Then
>                          DoCmd.FindRecord txtSearchBox
>                          Me.txtBlank.SetFocus
>                         Me.txtSearchBox.Value = Null
>                     End If
>         Else
>               If Me.cboQuickSearch.Value = 3 Then ' Street Name
>                     Me.txtFullStreetName.SetFocus
>                     If Not IsNull(txtSearchBox) Then
>                           DoCmd.FindRecord txtSearchBox
>                           Me.txtBlank.SetFocus
>                           Me.txtSearchBox.Value = Null
>                     End If
>         Else
>                If Me.cboQuickSearch.Value = 4 Then ' Designation
>                      Me.txtAddressDesignation.SetFocus
>                      If Not IsNull(txtSearchBox) Then
>                           DoCmd.FindRecord txtSearchBox
>                           Me.txtBlank.SetFocus
>                           Me.txtSearchBox.Value = Null
>                      End If
>        Else
>               If Me.cboQuickSearch.Value = 5 Then ' Box / PO Box
>                     Me.txtAddressBoxNumber.SetFocus
>                     If Not IsNull(txtSearchBox) Then
>                           DoCmd.FindRecord txtSearchBox
>                           Me.txtBlank.SetFocus
>                           Me.txtSearchBox.Value = Null
>                      End If
>         Else
>                If Me.cboQuickSearch.Value = 6 Then ' City
>                       Me.txtAddressCity.SetFocus
>                       If Not IsNull(txtSearchBox) Then
>                             DoCmd.FindRecord txtSearchBox
>                             Me.txtBlank.SetFocus
>                             Me.txtSearchBox.Value = Null
>                        End If
>          Else
>                 If Me.cboQuickSearch.Value = 7 Then ' State
>                        Me.txtAddressState.SetFocus
>                        If Not IsNull(txtSearchBox) Then
>                             DoCmd.FindRecord txtSearchBox
>                             Me.txtBlank.SetFocus
>                             Me.txtSearchBox.Value = Null
>                        End If
>           Else
>                 If Me.cboQuickSearch.Value = 8 Then ' Zip Code
>                        Me.txtAddressPostalCode.SetFocus
>                        If Not IsNull(txtSearchBox) Then
>                        DoCmd.FindRecord txtSearchBox
>                        Me.txtBlank.SetFocus
>                        Me.txtSearchBox.Value = Null
>                 End If
>     End If
>     End If
>     End If
>     End If
>     End If
>     End If
>     End If
>     End If
>
>     End Sub
>
> Thank you for your suggestions?

Private Sub txtSearchBox_AfterUpdate()
    Dim strField As String
    Select Case Me.cboQuickSearch.Value
        Case 1: strField = Me.txtCompanyID.ControlSource
        Case 2: strField = Me.txtAddressStreetNumber.ControlSource
        Case 3: strField = Me.txtFullStreetName.ControlSource
        Case 4: strField = Me.txtAddressDesignation.ControlSource
        Case 5: strField = Me.txtAddressBoxNumber.ControlSource
        Case 6: strField = Me.txtAddressCity.ControlSource
        Case 7: strField = Me.txtAddressState.ControlSource
        Case 8: strField = Me.txtAddressPostalCode.ControlSource
        Case Else
            MsgBox "Invalid selection", vbExclamation
            Exit Sub
    End Select
    Me.Filter = "[" & strField & "] Like '" & Me.txtSearchBox & "*'"
    Me.FilterOn = True
    Me.txtBlank.SetFocus
    Me.txtSearchBox.Value = Null
End Sub

You also could add a (third, I think) hidden column to the ComboBox
rowsource that contains the name of the control to get the focus.
Hidden means that it's column width is 0.
Then the whole Select Case structure could be reduced to one line:
    strField = Me.Controls(Me.cboQuickSearch.Column(2)).ControlSource

-- 
Regards,
Wolfgang 


0
Wolfgang
6/3/2010 8:29:41 AM
Thank you very much Wolfgang,

The code looks a lot shorter and neater AND IT WORKS!  I'm quite please
because I got a straight answer without having to spend a couple of days
trying to solve it.

Wolfgang Kais wrote:
>Hello mcc.
>
>> I created a cboQuickSearch combo box, where I can choose the field I
>> would like to search on. The txtSearchBox text field is where I enter
>[quoted text clipped - 85 lines]
>>
>> Thank you for your suggestions?
>
>Private Sub txtSearchBox_AfterUpdate()
>    Dim strField As String
>    Select Case Me.cboQuickSearch.Value
>        Case 1: strField = Me.txtCompanyID.ControlSource
>        Case 2: strField = Me.txtAddressStreetNumber.ControlSource
>        Case 3: strField = Me.txtFullStreetName.ControlSource
>        Case 4: strField = Me.txtAddressDesignation.ControlSource
>        Case 5: strField = Me.txtAddressBoxNumber.ControlSource
>        Case 6: strField = Me.txtAddressCity.ControlSource
>        Case 7: strField = Me.txtAddressState.ControlSource
>        Case 8: strField = Me.txtAddressPostalCode.ControlSource
>        Case Else
>            MsgBox "Invalid selection", vbExclamation
>            Exit Sub
>    End Select
>    Me.Filter = "[" & strField & "] Like '" & Me.txtSearchBox & "*'"
>    Me.FilterOn = True
>    Me.txtBlank.SetFocus
>    Me.txtSearchBox.Value = Null
>End Sub
>
>You also could add a (third, I think) hidden column to the ComboBox
>rowsource that contains the name of the control to get the focus.
>Hidden means that it's column width is 0.
>Then the whole Select Case structure could be reduced to one line:
>    strField = Me.Controls(Me.cboQuickSearch.Column(2)).ControlSource
>

-- 
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-modules/201006/1

0
lmcc
6/3/2010 3:44:35 PM
Reply:

Similar Artilces:

Filters *SOS* Filters *SOS* Filters *SOS*
1) On formLoad, I need to show only those items which are unassigned. 2) I need for the end-under to select only the items they are assigned to. 3) I need an option to select "ALL" so I can view all items. Any insight offered would be appreciated!!! On Wed, 29 Aug 2007 16:24:01 -0700, valdaiway <valdaiway@discussions.microsoft.com> wrote: >1) On formLoad, I need to show only those items which are unassigned. Use a query to put a criterion on the field that defines the assigned status. I assume you know how that information is stored in your table; nobody here does, ...

Criteria for Advanced Filter HELP
I have what I think is a simple question that I need answered IMMEDIATELY. I have a spreadsheet with 20 fields and I want to filter it so it only shows records that have something in of any of 5 of those fields. So once filtered, I will not have any records that have all 5 of those fields blank. I know I have done this before but I'll be damned if I can remember or find out how. -- Thanks You all are teaching me so much don't cross-post -- answer supplied in misc NG "knowshowrosegrows" <knowshowrosegrows@discussions.microsoft.com> wrote in message news:ACBC0...

Employee Filters
Hello: On the employee filters in the HR Preferenes window, would this restrict seeing employee information in both Payroll and HR? Also, would it restrict reporting on certain employees in a division or department? Thanks! childofthe1980s Your message does not indicate which version of Great Plains you are using. Using 8.0 with SP3 applied, HR filters do apply to some of employee information outside of HR. The settings will filter selected forms, Smartlists and Lists items. The HR filter setting do not apply to reports outside of HR. The filtered forms are: Employee Maintenance,...

Filtering based on a filter
Hello, I have an Excel Worksheet with a Pivot Table at the top with a Filter and a data set returned from a DB2 database below it. I would like to filter the DB2 data set based on the Pivot Table filter that is enabled. Any ideas? Thanks! James, You can't filter two ranges on the same worksheet. You can, instead, drill-down on your pivot table, which will show all items that go into the value on a newly created separate sheet. The drawback to that is that you cna only drill down on one item at a time, and it is a separate sheet. HTH, Bernie MS Excel MVP "James" <an...

Show Alll records Types relating to PersonID
I'm Trying to create a charge report from a tbl called tblcharges which has the following ClaimID PersonID DOSFrom DOsTo Procedure Fee BillTo which is a combo box and has a macro event which is a requery and the following sql code In this combo box patient could have 2 insurances example Medicare which is Primary And Medical which Is Secondary and this will be stored in the tblPeopleInsurance.Type Field which are P = Primary and S= Secondary. Lets Say I will select Medicare because this is the patient primary insurance. SELECT tblPeopleInsurance.GuaranterID, tblPeopleInsurance.PersonID, ...

Question on the IMF filtering in exchange...
Hey I installed the IMF filter last night and it works great, with one exception. I set both thresholds to the same (5) and got almost all blocked emails into the archive that were junk...So that is good. However I had some users report that there was mail in their junk folder that should have been good Inbox mail. This I undersyand and can live with as folas-positives...the problem is, since both settings on the folter tab were set to 5, how does it know to send the mail to archive rather than Junk folder? Why wouldn't it just send them all to archive if both settings were at ...

Filtering without Filter
I just don't get the following. Any ideas? "A" row I have two different values I use: "Contact" and "Not a contact". "B" row I have the person's name (employee). "C" row I have a quantity, just one number. Now what I need is to output quantities of how many Contacts Employee1 or Employee2 or Employee3 have. Also what I need is to get the number of contacts - which can be found on row "C". Should I use COUNT.IF ? Row A can have 2 or more different values so should there be somekind of conditional IF function included? T...

Filtering #11
Hi, can ayone tell me how I could do the following in excel 2007 or 2010: Horse Trainer Sam M Jones John M Jones Colin S Attwater Steve J Jackson Brian B Mathers James B Mathers Martin G Raggy Patrick S Thomson What I want to do is filter the dataset on 'Trainer' so that it only shows me the Trainers who feature once in the list. So if I was to do this properly it would only show S Attwater and G Raggy as the other trainers have more than one horse..... Hopefully someone can help because it is driving me crazy !! Thanks David Give this macro a try... Sub HideDuplicateTr...

Junk filter BEFORE other filters?
I am running Outlook 2003 and the Junk filter was working really well. Then I started making other filters...one of them looks for my domain name in the headers and if it's there it moves the email to a folder. Problem is, this filter seems to activate before the junk filter, so the junk sn't being filtered now! How can I set the junk filter to do it's job first and THEN to run my own rules? -- Bryan Anderson <www.anderson-it.com> I created this rule and set it as the first rule to run: Apply this rule after the message arrives with 'X-Spam-Level:******'or'...

Pasting into a filtered list
Can anyone tell me if it is possible to paste a list of price updates into a filtered list. - I have filtered the list to show just the products whose prices need to be updated, when I try to paste the updated prices, into the list, the prices are not just pasted into the visible cells but the hidden cells between. Can I paste into the visible cells only or do I have to update each line manually. I am using Excel 2002 Any help would be much appreciated Can you sort the list to bring the products that need updating together in the list? If not, try something like this: Your list of product...

Macro to copy a VLOOKUP formula
Hello, I was wondering if somebody could help me with this macro… I have some data with a filter on, so that only the rows with blank cells are showing. I want to enter a VLOOKUP in the cell, and copy it down to all the blank cells. I tried just recording a macro, but when I run the macro it doesn’t work. Any ideas of how to do it? Example: 1) Before the filter: Colums A -B - C A x x - 1st Row A - 2nd Row A x x - 3rd Row A - 4th row A x x - 5th row 2) After the fil...

apply filter macro
I have a access db that works on win xp but does not work on win 2007 I have a combo box that triggers a apply filter macro using a query sort. no problem on win 2000 or win xp or win 2003 Help AlT ...

IP filtering based on corresponding MX records
Hello Dears, How can I implement the following? Used: Exchange 2003 SP2 in FE/BE configuration; FE is in perimeter zone (capable to “speak” with DNS, BE, DCs and retrieve info) So, somebody connects my FE to sent an e-mail to one of domain users. I need something like that: When connecting, see the “mail from: user@somedomain.xxx”; Verify if there is a record MX for the IP address from which the connection was established in DNS for the domain “somedomain.xxx” If not – drop connection (attention: MX record, not SPF) Is it possible with Exchange 2003 SP2 only? How? Thank you, Alex I be...

Month Filter
I keep a log of checks that I receive in my department throughout the year. I have the checks listed by date (mm/dd/yy), payee, check #, etc. What I want to do is be able to filter the list by month (ex., March 2005). Is there a way to do this? Thanks Joseph You can Try EasyFilter Joseph http://www.rondebruin.nl/easyfilter.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Joseph" <joe@nospam.com> wrote in message news:%23lQNnTawFHA.464@TK2MSFTNGP15.phx.gbl... >I keep a log of checks that I receive in my department throughout the year. I have the checks lis...

MTA problem with MX records?
Hey Anyone ever seen this problem? If so, what direction do I need to head to get it fixed 550-EarthLink does not recognize your computer ([IP]) as connecting from an EarthLink connection. If this is in error, please contact technical support ...is due to an improper MTA configuration with the host that is responsible for delivering outbound mail on your network. In a nutshell, the mailserver which attempted to deliver mail to the earthlink.net e-mail address was initially unable to successfully deliver the mail to the earthlink.net MX (more than likely due to high load on our end; no Eart...

Using a form in Excel to Filter
I would like to create a form in Excel that is similar to a form in Access. This form will hold all fields on the underlying spreadsheet and enable the user to sort using combo box dropdowns. Ideally, the form would have a button titled RUN that will take all the data the user selects in the combos and filter the underlying spreadsheet. Can this be done?? If so....you will save my life! TIA, Chris Try this Add-in http://www.rondebruin.nl/easyfilter.htm -- Regards Ron de Bruin http://www.rondebruin.nl <ccfatzin@ibtco.com> wrote in message news:1122677766.648239.226910@z14g200...

filter for missing values in a range
I have a list in Col A ( about 2000) one to four digit numbers. I would like to ( for example) , in the 700's be able to filter and find out which of the numbers from 700 to 799 is NOT in the list. I know how to copy and paste to another col, etc. Thanks in advance for the wonderful help all of you give. One play .. Assume your source data runs in A2 down In B2: =IF(ROWS($1:1)+700-1>799,"",IF(ISNUMBER(MATCH(ROWS($1:1)+700-1,A:A,0)),"",ROWS($1:1)+700-1)) Copy B2 down by 100 rows to cover the full spread of numbers to be checked, ie # of nums from s...

filter driver for an USB modem
Hello, I am working on a NDIS filter under Windows 7 64 bits. The filter is working well as NetService Class with classical Ethernet Adapters. But, it does not work with an USB Modem with "Modem" class. Packets handled by the modem are not sent to the filter. How can I get them ? I suspect I should register the driver in another manner. Regards. Eric Boudrand > Packets handled by the modem are not sent to the filter. How can I get = > them ? I suspect I should register the driver in another manner. You need to support PPP in your filter, this requires ...

Filtering
Is there a way to filter messages that contain embedded images? Or even better, messages that only contain embedded images and no text? thanks, Andy andyp@repcmi.com ...

Reverse filter?
Hello, Is there a way to do a "reverse" filter. I'd like to be able to hide or delete rows that match specified criteria. Thank you, Marc Hi Marc, Unfortunately not, but depending on how you are filtering you might be able to use =NOT(oldformula) For the autofilter you might have to use another column (F) F1: 'white -- value of cell you don't want to match F2: =TRIM(F$1)<>TRIM(E2) and fill down --- HTH, David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001] My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel...

Data Filter Question
When I am trying out different data filter criteria, is there an easy and fast way to go back to displaying *all* data without clicking on the drop arrow and selecting All? I am using Excel 2003. Thank you. I've added an icon to my favorite toolbar: Tools|Customize|Commands tab|data category Drag the "Show All" (and maybe autofilter) icon to a toolbar. john.menken@ceridian.com wrote: > > When I am trying out different data filter criteria, is there an easy > and fast way to go back to displaying *all* data without clicking on > the drop arrow and selecting All? ...

recording email discussions
This ought to be simple. It doesn't seem to be! I get involved in a lot of email discussions with staff in various sites. Evidence of these discussions needsto be made available to auditors - mostly to prove that the discussions occurred, also to gauge the level of participation among different sites, and the content. Academic auditors are picky! Auditors won't get access to my email folders. The ideal would be for me to be able to select all the email messages that I want to show as evidence - from a variety of folders probably - and have them exported to a text file/Word document/...

Selecting particular records #2
Hi I have an excel sheet with dialog box having default values.I wan particular records from the sheet when I click any value in the dialo box.Like when I click the first value it should show me the 1-5 records and for the second value it should show next 50 records in th sheet.I would appreciate if someone helps me. Thank -- Message posted from http://www.ExcelForum.com Hi, If no one else responds, send me a sample sheet or your workbook up to 1mb, and I will write something for you. Please provide as much info as possible. But what you may need are scroll bars that, when moved, show...

Filtering Low Cardinality Columns on SQL 2005
I have a view which is a 5 table join. One of those tables is 1.5million rows. When doing select on this view, the conditions are as follows: 1. compare if equal a column to a literal, with 2 distinct values, 2. compare if equal column to a literal, with 5 distinct values, 3. compare if equal column to a literal, with329 distinct values, 4. compare if less than date column to literal, with 1.2 distinct values All of the above columns are from the large table, mentioned above. This table has a compound primary key. Looking at explain plan, an index scan is being performed ...

Avoiding Redundant Records
It is my understanding that surrogate keys are generally recommended to ensure uniqueness of records. Is it not true that using surrogate keys implies taking extra precautions to prevent duplicate records? I mean, with surrogate keys there is nothing to prevent the proliferation of multiple records all containing the same data, but each having a unique key. I would appreciate your help with this in the following context: AGREEMENTS AgrmtID (PK) InsuredID Agrmt fields… CERTS CertID (PK) AgrmtID ProducerID Cert fields… POLICIES PolicyID (PK) InsuredID PolicyTypeCo...