How to Insert Character ( ' ) in Access

Kashif
11-28-2006, 12:39 AM
Hi All Members.

I'm Using Execute Method to Insert Values from Vb 6.0 Interface into Microsft Access Database.

I want to ask if User TYPE ( ' ) Character in a Chracter type Field. How do i Insert that Value in the Database Using the Execute Method of a Connection Type Object.

gb711825
11-28-2006, 12:48 AM
Look for Chr(39) in your textbox

Or just refer to the textbox in your SQL statement. It should not matter what the contents of the textbox is.

strInsert = "INSERT INTO Table(field) VALUES( '" & me.Textbox & "')"
cn.execute strInsert

jutsu
11-28-2006, 12:56 AM
You have to replace the (') with ('') or otherwise you'll get an error.. Dim a As String
a = "'mama"
a = Replace(a, "'", "''")

Kashif
11-28-2006, 12:56 AM
Here is my SQL Statment

mySQL = "INSERT INTO A_LVL2 VALUES (" & txtAcctCode & "," & "'" & txtDesc & "'" & "," & LVL1Code & ")"
con.Execute (mySQL)

Kashif
11-28-2006, 01:05 AM
You have to replace the (') with ('') or otherwise you'll get an error..

Is there no Way to Insert Single Quote in the Database. because this the Requirement.
Replacement is not the Solution.

NEOLLE
11-28-2006, 01:07 AM
Just apply jutsu's recommendation

mySQL = "INSERT INTO A_LVL2 VALUES (" & txtAcctCode & ",'" & Replace$(txtDesc,"'","''") & "'," & LVL1Code & ")"
con.Execute (mySQL)

Just a tip, its better to specify which the fields you will be inserting. This will cause an error if your database will be modified - like adding a new column, re-order the column assignment or a column is removed.

jutsu
11-28-2006, 01:08 AM
That will insert only a single (') not (''). Try it first..

gb711825
11-28-2006, 01:15 AM
Sorry guys, dont know what I was thinking there. Of course the single quote will cause an error and yes, you'll need the Replace(). :/

Kashif
11-28-2006, 03:16 AM
That will insert only a single (') not (''). Try it first..


Thank u jutsu. its Working and insertng Single (').
i was thinking that by Replacing it will Replace (') with (").

Thanks u again.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum