Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Storing appostrophe's in SQL

I have a text box that allows the user to type in free
form text. I want to save it to a SQLServer database
table. If the user types in <Here's Johnny!, I can insert
it into SQLServer by inserting the text string <Here''s
Johnny!

My question: is there a function that does this, or do I
process the text string before I insert it to double all
the appostrophe's?

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Storing appostrophe's in SQL

Hi Jeff,
for example:
Function FixApostrophy(ByVal sSQL As String) As String
Dim sPhrase As String, wLength As Integer, m As Integer
wLength = Len(sSQL)
For m = 1 To wLength
If Mid(sSQL, m, 1) = "'" Then
sPhrase = sPhrase & "''"
Else
sPhrase = sPhrase & Mid(sSQL, m, 1)
End If
Next
FixApostrophy = sPhrase
End Function

MP

"Jeff" a écrit dans le message de
...
I have a text box that allows the user to type in free
form text. I want to save it to a SQLServer database
table. If the user types in <Here's Johnny!, I can insert
it into SQLServer by inserting the text string <Here''s
Johnny!

My question: is there a function that does this, or do I
process the text string before I insert it to double all
the appostrophe's?

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Storing appostrophe's in SQL

Hi Jeff,

If your code will always be running on Excel 2000 or higher versions of
Excel you can use the VBA Replace function to do this.

Dim szSQLString As String
szSQLString = Replace(txtEntry.Text, "'", "''")

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Jeff" wrote in message
...
I have a text box that allows the user to type in free
form text. I want to save it to a SQLServer database
table. If the user types in <Here's Johnny!, I can insert
it into SQLServer by inserting the text string <Here''s
Johnny!

My question: is there a function that does this, or do I
process the text string before I insert it to double all
the appostrophe's?

Thanks!



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Storing appostrophe's in SQL

That's a great solution for when we migrate everyone to =
Excel 2000. But for now I have a lot of users on '97.

Thanks - Jeff

-----Original Message-----
Hi Jeff,

If your code will always be running on Excel 2000 or

higher versions of
Excel you can use the VBA Replace function to do this.

Dim szSQLString As String
szSQLString = Replace(txtEntry.Text, "'", "''")

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Jeff" wrote in

message
...
I have a text box that allows the user to type in free
form text. I want to save it to a SQLServer database
table. If the user types in <Here's Johnny!, I can

insert
it into SQLServer by inserting the text string <Here''s
Johnny!

My question: is there a function that does this, or do I
process the text string before I insert it to double all
the appostrophe's?

Thanks!



.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Storing appostrophe's in SQL

Hi Jeff,
you can use Application.Substitute
Dim szSQLString As String
szSQLString = Application.Substitute(txtEntry.Text, "'", "''")

MP

"Jeff" a écrit dans le message de
...
That's a great solution for when we migrate everyone to =
Excel 2000. But for now I have a lot of users on '97.

Thanks - Jeff

-----Original Message-----
Hi Jeff,

If your code will always be running on Excel 2000 or

higher versions of
Excel you can use the VBA Replace function to do this.

Dim szSQLString As String
szSQLString = Replace(txtEntry.Text, "'", "''")

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Jeff" wrote in

message
...
I have a text box that allows the user to type in free
form text. I want to save it to a SQLServer database
table. If the user types in <Here's Johnny!, I can

insert
it into SQLServer by inserting the text string <Here''s
Johnny!

My question: is there a function that does this, or do I
process the text string before I insert it to double all
the appostrophe's?

Thanks!



.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
storing macros ? Tim[_7_] Excel Discussion (Misc queries) 2 October 26th 07 02:54 AM
Storing a value to variable CLamar Excel Discussion (Misc queries) 0 June 16th 06 04:46 PM
storing data JK57 Excel Worksheet Functions 3 May 1st 06 12:16 AM
Storing Macros jc lewis Excel Programming 1 June 28th 04 01:30 PM
Storing Variables Todd Huttenstine[_3_] Excel Programming 5 November 27th 03 02:14 AM


All times are GMT +1. The time now is 09:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"