Hi, Jorge.
if they enter apostrophy the code breaks
how can i overcome that in cod.
If you want to avoid apostrophes in the text being used inappropriately in a
SQL statement, then you may use the Replace( ) function to replace a single
quote with two single quotes. For example:
Private Sub UpdateBtn_Click()
On Error GoTo ErrHandler
Dim sqlStmt As String
Dim sReplace As String
sReplace = Replace(Me!txtCoName.Value, "'", "''")
sqlStmt = "UPDATE tblCustomers " & _
"SET CoName = '" & sReplace & "' " & _
"WHERE ID = " & Me!txtID.Value
CurrentDb().Execute sqlStmt, dbFailOnError
Exit Sub
ErrHandler:
MsgBox "Error in UpdateBtn_Click( ) in " & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear
End Sub
.. . . where txtCoName is the name of the text box that may contain
apostrophes, tblCustomers is the name of the table to be updated, CoName is
the name of the field that needs the company name, txtCoName is the text box
bound to this field, ID is the primary key, and txtID is the text box bound
to this field.
If you have other problems besides the embedded apostrophes, then please
post your code and we'll try to help.
HTH.
Gunny
See
http://www.QBuilt.com for all your database needs.
See
http://www.Access.QBuilt.com for Microsoft Access tips.
(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.