Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need assistance with Search 1

Status
Not open for further replies.

aledid

IS-IT--Management
Sep 16, 2002
22
US
Hello,

I am a newer user and I have been trying to make a field that will search my Name table. I have had seen forms that have a search field the will search tables for specific information from a specified table.

I want to be able to put the user's fist name in a search field and have it bring up the rest fo the information for that specific user. Any help would be appreciated.
 
In the header section of the form place a text box control.
Int the AfterUpdate event of this control place the following code

Code:
Private Sub txtFirstFind_AfterUpdate()
Me.RecordsetClone.FindFirst "FirstName = " & txtFirstFind
If Me.RecordsetClone.nomatch Then
      MsgBox "No matching record"
Else   
      Me.Bookmark = Me.RecordsetClone.Bookmark
End If 
End Sub

That will find the first occurance of the text in txtFirstFind that appears in the FirstName field.


IF there is a change that you'll match multiple records with the first name then use

Code:
Private Sub txtFirstFind_AfterUpdate()
If IsNull(txtFirstFind) Then
    Me.FilterOn = False
Else
    Me.Filter = "FirstName = '" & txtFirstFind & "'"
    Me.FilterOn = True
End If
Exit Sub



'ope-that-'elps.

G LS
 
Thank you for the follow up!!!!
I tried the following information you provided. I think that I am leaving out a step. Here is my test db. I want to be able to search for Ryan’s name in the search field and bring up all his favorite information.



Search > Ryan

First Name> Todd Favorite Food> Sushi Favorite TV Show> Banana Splits
Brian Carrots Ninja Turtles
Ryan Pizza Mamas Family

I added the code below at the Text box properties\ Event\ After Update under the Event procedure and saved the changes. Afterwards I would enter the Ryan’s name and under the First Name field and I would be able to change the name and not pull up his information. Let me know if this makes sense or if you need further information.

In the header section of the form place a text box control.
Int the AfterUpdate event of this control place the following code

Private Sub txtFirstFind_AfterUpdate()
Me.RecordsetClone.FindFirst "FirstName = " & txtFirstFind
If Me.RecordsetClone.nomatch Then
MsgBox "No matching record"
Else
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End Sub

 
As txtFirstFind contains text you need the single quotes ( Which I accidentally omitted from the first example - but managed to creep into the second ! )


Code:
Me.RecordsetClone.FindFirst "FirstName = '" & txtFirstFind & "'"

'ope-that-'elps.

G LS
 
I tried using the codes listed here (using PhoneNumber as field) and each time I search, it returns the "No Matching Record" error. Any help would be appreciated. Thanks!
 
Post the actual code you are using and we'll have a look at it.



G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Ok! Here is the code I am using....

Private Sub Text45_AfterUpdate()
Me.RecordsetClone.FindFirst "PhoneNumber = '" & txtFirstFind & "'"
If Me.RecordsetClone.NoMatch Then
MsgBox "Customer Not Found!"
Else
Me.RecordsetClone.Bookmark
End If
Exit Sub
End Sub

Thanks,
Tony
 
Okay Tony - so now we can see what your problems are


Point 1.
You have failed to rename the control from its defailt value of Text45 to a more appropriate and useful value before.


Point 2.
The fact that this code runs at all means either:-
a, You have a control ( or variable ) called txtFindFirst floating around your design
OR - more likely
b, You have not specified Option Explicit in you module headers - Which is dangerous.
If b, is the case then to fix it go to Code window and in the Tools menu Options, click on the Editor tab and put a tick in the "Require Variable Declaration" box. You then need to add "Option Explicit" underneath "Option Compare Database" in all existing Code and global modules - then recompile.

Point 3,
In the sample code provided the term txtFindFirst MATCHES the name of the contol who's AtferUpdate event is firing.
So you need to chage one or the other to make them match.
( This is you REAL problem )




'ope-that-'elps.



You need to make sure that the G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.

Please remember to give helpful posts the stars they deserve!
This makes the post more visible to others in need! :-D

 
Thank You!!!! I Greatly Appreciate Your Help!
:-> :-> :-> :-> :->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top