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.)