|
-
Jul 5th, 2000, 03:31 PM
#1
Thread Starter
Addicted Member
Using VB6/ADO/Access MDB file...
I have a table that contains a field that [in some cases] will contain an apostrophe ' and when I try to query for the name O'BRIEN for instance with the following code...
Code:
adoRset.Open "SELECT * FROM table WHERE lastname = '" & txtLastName.Text & "' ORDER BY lastname", adoConn
I get an error of Syntax error (missing operator) in query expression 'employee LIKE '%O'BRIEN%''.... any ideas how to get around this problem?
-
Jul 5th, 2000, 04:49 PM
#2
Hyperactive Member
-
Jul 5th, 2000, 04:52 PM
#3
Frenzied Member
You could scan your string for apostrophe's and, if you find one, use an alternative statement.
adoRset.Open "SELECT * FROM table WHERE lastname = " & """" & txtLastName.Text & """" & " ORDER BY lastname", adoConn
is equivalent to what you're using. Of course, if there are any names with quotes in them, you'll be hosed...
-
Jul 5th, 2000, 11:03 PM
#4
Guru
All you have to do is replace the apostrophies with 2 apostrophies (not a quote) (ex '='')
just use the VB6 REPLACE function
Code:
adoRset.Open "SELECT * FROM table WHERE lastname = '" & replace(txtLastName.Text, "'", "''") & "' ORDER BY lastname", adoConn
it works every time
-
Jul 6th, 2000, 11:11 AM
#5
Frenzied Member
-
Jul 6th, 2000, 11:18 AM
#6
Thread Starter
Addicted Member
Thank you all for your help. Go figure why 'O''Brien' fixed the problem, but who am I to critique it?!?
Thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|