VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



SQLFix

by Jeremy H (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

Corrects for reserved SQL characters in SQL queries. This will correct your SQL statement if an apostrophe or 'pipe' character is in the SQL query. It is a better fix than the SQL functions which replace ' with '' because those will actually still fail in certain situations (such as in FindFirst commands).

Inputs
Bad SQL statement as string
Code Returns
Proper SQL Statement as string

Rate SQLFix

Public Function SQL_Fix(ByVal sSQL as string) as string
  Dim sTempSQL as string
  'replace apostrophes
  sTempSQL = Replace(sSQL, "'", "' & Chr(39) & '")
  'replace pipe symbols
  SQL_Fix = Replace(sTempSQL, "|", "' & Chr(124) & '")
End Function

Download this snippet    Add to My Saved Code

SQLFix Comments

No comments have been posted about SQLFix. Why not be the first to post a comment about SQLFix.

Post your comment

Subject:
Message:
0/1000 characters