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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with memo and Text 1

Status
Not open for further replies.

easycode

Programmer
Jan 28, 2005
195
US
Hi all,

I am having a problem with a memo field and a string var,
------------------------------------------------------
this is the code:

Sub writef(OrgValue as string, Curvalue as String)
Dim fsql as String

fsql = "INSERT INTO AuditTable Values("'" & OrgValue & "', '" & CurValue & "')"

CurrentDb.Execute fsql
--------------------------------------------------------

Orgvalue and CurValue are 2 string vars that containts free text to be save in 2 memo fields.

the above code works as long as i dont include ' or " in vars OrgValue or CurValue, otherwise i got a Syntax error message

If these 2 vars are free text How can i prevent from happening this error, The only way i see is letting users know they are not allowed to enter (') or (").

 
Wrap a Replace function around your OrgValue and CurValue variables.

This will replace all instances of the single quote in the OrgValue variable with a blank space.

Replace(OrgValue, "'", " ")
 
that's a good idea but, i need to keep the single quotes (') and quotes (") in the memo fields, so i must find a way to get rid of the error without getting rid of the ' ".
 
And if you want to keep any quote ...
fsql = "INSERT INTO AuditTable Values[tt]('" & Replace(OrgValue, "'", "''") & "','" & Replace(CurValue, "'", "''") & "')"[/tt]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
by the way Thank you for replying rjoubert, it's appreciated
 
Thank you both for replying.

PHV that's a good one.
 
I think the * anwser your question, Thanks again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top