Solved

Another Access 2007 Search Question

Posted on 2011-09-08
7
355 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
Very good!
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

19 Experts available now in Live!

Get 1:1 Help Now