INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Select Statment doesn't find existing record, when matching text field

Select Statment doesn't find existing record, when matching text field

Select Statment doesn't find existing record, when matching text field

(OP)
Hi all,

I'm trying to run a simple check for an existing record to update, but for some reason my Select statement doesn't find the record with the matching text field in my Access table, even though it exists.  If I switch over and use an integer field with the same select statement it finds the matching record no problem.

Is there some x factor to matching text fields that I am missing.  I'm new to this so bear with me if I'm missing something obvious.  Here's the code:

CODE

sSql = "SELECT * From DictationLog WHERE DictationLog.[OJobNumber]=" & sJobNum
Set rCurrRec = dLog.OpenRecordset(sSql)

The string variable sJobNum absolutely perfectly matches the OJobNumber (text, 9) field in the Access DB.  It won't find a match even if I hard code the string in place of that variable.

However, if I switch the statement to evaluate against a different field, which is an Integer field and feed it a matching integer variable, it finds the match with no problem.  

Any advice appreciated!  

Thanks,
AJ

 

RE: Select Statment doesn't find existing record, when matching text field

You need to use a delimiter for your data.  Like this:


sSql = "SELECT * From DictationLog WHERE DictationLog.[OJobNumber]='" & sJobNum & "'"


Now... your query should work just fine unless your sJobNum contains a single quote.  If it does, you'll get a different error.  To handle this problem, you need to replace a single quote to 2 single-quotes, like this...

CODE

sSql = "SELECT * From DictationLog WHERE DictationLog.[OJobNumber]='" & Replace(sJobNum, "'", "'") & "'"

Ok.... you might be thinking, "I can't have single quotes in my Job Number".  And you may be right.  But, I would still encourage you to use replace and make it a habit so that when you are dealing with other types of string data, you won't forget to do this.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom

RE: Select Statment doesn't find existing record, when matching text field

(OP)
Yep.  That did the trick.  I'll implement the Replace logic too.  I'm with you on that one.

Thanks very much, George.  Tek-Tips FTW.   

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close