View Single Post
 
Old March 9th, 2005, 04:29 PM
BrianWren BrianWren is offline
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Perhaps part of the problem is that this code (as written) won’t quite work (though it almost will)
Code:
    stName = "John Doe"
    stSQL = "SELECT * FROM tblYourTable WHERE Name = " & stName
    Access (indeed, [u]all</u> databses) require literal strings to be delimited.
This needs to either be
Code:
    stName = """John Doe"""
    stSQL = "SELECT * FROM tblYourTable WHERE Name = " & stName
    or
Code:
    stName = "John Doe"
Code:
    stSQL = "SELECT * FROM tblYourTable WHERE Name = """ & stName & """"
    When VB is in literal mode, interpreting a string, and it hits a pair of doublequotes, it adds 1 double quote to the string. So either of those snippets provided will create
Code:
    SELECT * FROM tblYourTable WHERE Name = "John Doe"
In your code provided
Code:
    stSQL = "SELECT * FROM Athletes WHERE LastName = " & Name
you would need
Code:
    stSQL = "SELECT * FROM Athletes WHERE LastName = """ & Name & """"
(unless the string, Name, already has quotes within it.)