Alter a String in a VB program for use in an SQL statement

Category:
Database
Type:
Snippets
Difficulty:
Beginning
Author:
Intelligent Solutions Inc.

Version Compatibility: Visual Basic 6, Visual Basic.NET

More information:
When using strings as values in SQL Statements, you must precede and end the value with single quotes, and replace any single quotes (apostrophe) within the string with an additional quote (e.g., ' must become ''). This function handles all this .

The replace method, which is only available in VB6 or higher is used here. If you want to do the same thing in an earlier version, check out This code sample which provide a version of the replace function for VB5.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: