I know I'm missing something

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

Thanks for reading this.
What I'm trying to do is to create a query though code that will display last
names of the text box.

For example: Person's last name is James. There may be 5 names with the last
name of James.

strWhere = "Select [lname]" _
& "From tbl_roster " _
& "Where lname =' " & txtSearch & ' '"

Every time I do a msgbox it comes up with the wrong name. I know I've seen
the correct way to do it here, but do you think I can find it? NOT.

The txtSearch is a textbox to enter the person's last name.

Once I can get this working then I think all I have to do to display the next
name/James would be to press my Next command button.

Your help is greatly appreciated.
 
A

Afrosheen via AccessMonster.com

thanks for your reply Daniel. It worked the way it should have.
I appreciate the help.

Daniel said:
A few minor mistake in your SQL synthax. Try:

strWhere = "SELECT lname" & _
" FROM tbl_roster " & _
" WHERE lname = '" & txtSearch & "'"
Thanks for reading this.
What I'm trying to do is to create a query though code that will display last
[quoted text clipped - 16 lines]
Your help is greatly appreciated.
 
J

John W. Vinson

A few minor mistake in your SQL synthax. Try:

strWhere = "SELECT lname" & _
" FROM tbl_roster " & _
" WHERE lname = '" & txtSearch & "'"

One additional problem that will come up occasionally: if you use a
singlequote character ' to delimit the names, then you'll have problems if the
name contains an apostrophe (O'Niell for example). It's safer to delimit with
" characters (which won't usually occur in last names; I've seen them as
nicknames, e.g. William "Bud" Wilson, but I think you can ignore this
possibility).

I'd use

" WHERE lname = """ & txtSearch & """"

Doubling a doublequote within a doublequote delimited string will be
translated to a single doublequote (how's that for doubletalk!)
 

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