Results 1 to 2 of 2

Thread: SQL Apostrophe problems...

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    34

    Cool

    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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Here are some functions I use to correct this problem

    Code:
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width