Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error handling routine

Status
Not open for further replies.

spacehawk

Programmer
May 17, 2000
30
0
0
US
When users enter text with , or ' in a form they get an error message and the database does not update.&nbsp;&nbsp;Can I write a simple error handling routine that looks for the characters that are not allowed and replaces them with characters that will work?<br><br>Could anyone get me started on this?<br><br>Thanks.
 
This'll do the trick.<br><br>Function PrepForSQL(strDirty)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Dim strClean<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If IsNull(strDirty) OR Trim(strDirty) = &quot;&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrepForSQL = &quot;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Exit Function<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strClean = Trim(strDirty)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Replace all single quotes with 2 single quotes<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strClean = Replace(strClean, Chr(39), Chr(39) & Chr(39), 1, -1, 1)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrepForSQL = strClean<br>End Function <p> Jeff Friestman<br><a href=mailto: > </a><br><a href= View my Brainbench transcript</a><br>Brainbench 'Most Valuable Professional' for ASP<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top