Search for Record

P

ploddinggaltn

I'm using this code to search for records with a form with one field in view
as the search sourse. Once the find cmdbutton is clicked, the remaining
fields on the form become visible with the data for that record. I have two
issues, one is the search only brings back one result when there are 3
records with the same last name (last name is the search criteria). The
other issue is some of my lables are not appearing when the Find cmdbutton is
clicked. I've tried copying the formatting for labels that do appear and
that is not working...any ideas for either of these issues is appreciated.
Thank you...here is my code.

Private Sub cmdFindStudent_Click()

Dim ctlx As Control
For Each ctlx In Me.Controls
If TypeOf ctlx Is TextBox Or TypeOf ctlz Is ComboBox Or TypeOf ctlz
Is Label Then
ctlx.Visible = True
End If
Next ctlx

DoCmd.ApplyFilter , "[LastName]= '" & txtLastName & "'"

End Sub
 
A

Allen Browne

The filtering looks correct, though it could fail if the surname contains an
apostrophy such as O'Brien.

I prefer to use:
Me.Filter = "[LastName] = """ & Me.txtLastName & """"
Me.FilterOn = True
Explanation of the quotes:
http://allenbrowne.com/casu-17.html

Regarding the labels, they hide then the control they are attached to hides,
but they also have their own Visible property. Any chance the Visible is No?
 
T

Tom van Stiphout

On Sat, 9 Feb 2008 12:25:27 +0900, "Allen Browne"

I prefer to double up on the single-quotes:
Me.Filter = "[LastName] = '" & Replace(Me.txtLastName,"'", "''") &
"'"
-Tom.
 
A

Allen Browne

Tom van Stiphout said:
I prefer to double up on the single-quotes:
Me.Filter = "[LastName] = '" & Replace(Me.txtLastName,"'", "''") & "'"

Tom, the difficulty I have with doubling the single (or double) quotes
arises when you have functions that call other functions to build the
strings. That's pretty common, but I don't know how to determine at what
level the replace needs to be done.

It might sound corny, but what I generally do is to disallow the
double-quote character in data (and document it.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top