PDA

Click to See Complete Forum and Search --> : SQL Apostrophe problems...


wick77
Jul 13th, 2000, 11:41 AM
Im am using textboxes bound to my database using DAO. I am using a query based on the information in the textbox. My problem is that when an apostrophe is entered in the box I get an error. I understand its because the apostrophe is messing up the SQL query syntax. Is there anyway around this so I can enble users to enter apostrophes.

Help would be appreciated, thanks,
Wick

Negative0
Jul 13th, 2000, 11:50 AM
Here are some functions I use to correct this problem

Public Sub FixFormQuotes(glCallfrm As Form)
Dim mycontrol As Control
For Each mycontrol In glCallfrm.Controls
If TypeOf mycontrol Is TextBox Then
mycontrol.Text = FixQuotes(mycontrol.Text)
End If
Next

End Sub
Public Function FixQuotes(A As String)

Dim i As Integer
i = InStr(A, "'")

Do While i > 0
A = Left(A, i) & Mid(A, i)
i = InStr(i + 2, A, "'")
Loop

FixQuotes = A

End Function

You can use FIXQUOTES to fix any string, or FixFormQuotes to fix all text boxes on a form.

Hope this helps