Solved

Another Access 2007 Search Question

Posted on 2011-09-08
7
357 Views
Last Modified: 2012-06-27
I have the following coding that will find Alias1, Alias2, Alias3, Alias4, and Alias5.  What If I have two or more records with the same Alias.  I need some coding to find records with the same Alias on any of the Alias1, Alis2, Alis3, Alias4, and Alias5.

I need a Find Next Button to find these records.  How can the VBA cdoing be written to do this?

My coding:

Private Sub Command9_Click()

Dim rs As DAO.Recordset

Set rs = Me.Recordset.Clone
rs.FindFirst "[Alias1] = '" & Me.Text10 & "' Or [Alias2] = '" & Me.Text10 & "' Or [Alias3] = '" & Me.Text10 & "' Or [Alias4] = '" & Me.Text10 & "' OR [Alias5] = '" & Me.Text10 & "'"
If rs.NoMatch = True Then
    MsgBox "There are No Records Found for this Alias Name.  Please Try Again"
    Me.Text10.SetFocus
Else
    Me.Bookmark = rs.Bookmark
End If
End Sub

Any help is appreciated.
0
Comment
Question by:jjc9809
  • 3
  • 3
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36502904
Try setting a filter:

Me.Filter = ""
Me.Filter =  "[Alias1] = '" & Me.Text10 & "' Or [Alias2] = '" & Me.Text10 & "' Or [Alias3] = '" & Me.Text10 & "' Or [Alias4] = '" & Me.Text10 & "' OR [Alias5] = '" & Me.Text10 & "'"
Me.FilterOn = True
0
 

Author Comment

by:jjc9809
ID: 36503036
Where do I place the coding?  Do you place in the original coding or have it under a Find Next button.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 36503074
Hi -

It's completely independent from the other code (don't mix them).

I'd recommend placing it behind a "Find", "Filter" or "Get Records" button (or some other meaningful label).

That code finds and displays all records meeting the specified criteria at once (so it is not a 'find next'... it gets all of them).
0
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.

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36503469

No points please, just expanding.

I like to use the filter method suggested by mbizup, but when more than one record matches the filter I also use a popup form that displays the records that match the criteria in a listbox.  In that case, I use the double click event of the listbox, to allow the user to identify the specific record they are looking for.
0
 

Author Comment

by:jjc9809
ID: 36503564
This will work, but I need a place to put an error mesage if no records are found at all.  I do not believe I can say If Me.Filter = Nothing display a message, because this is incorrect use of an object.
So how do i do this with the coding you provided.  Your coding is better than my original coding so I was going to use your coding for my Find Button becuase I am trying to find all records anyway with aan Alias Name.

jjc9809
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 36503713
Use the recordcount property...

Me.Filter = ""
Me.Filter =  "[Alias1] = '" & Me.Text10 & "' Or [Alias2] = '" & Me.Text10 & "' Or [Alias3] = '" & Me.Text10 & "' Or [Alias4] = '" & Me.Text10 & "' OR [Alias5] = '" & Me.Text10 & "'"
Me.FilterOn = True 
If me.recordsetclone.recordcount = 0 then msgbox "No records were found"

Open in new window


You also may want to add a button to toggle the filter off (clear the filter)

Me.Filter = ""
Me.FilterOn = False

Open in new window



___
fyed,

I use a similar approach in many applications.  If there are a bunch of fields that the user needs to be able to filter on, I place unbound controls for them and and an "Apply filter" button to a form, and use a mult-select listbox as you described for a quick view of the results,  to allow the user to select which record(s) to view.
0
 

Author Closing Comment

by:jjc9809
ID: 36504012
Very good!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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 …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

813 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now