473,585 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"wrapper" for raw INSERT INTO text?

Hi,

Question... Is there any way to put a wrapper on a raw string going
through SQL, or should I bite the bullet and use a recordset method
instead?

Situation:
I'm trying to have the user add comment data to a table. I calculate
and/or determine all of the variables except for that comment.

So, currently, I'm using an inputbox to grab a string, and then using
that string as part of an INSERT INTO SQL command...

strComments = InputBox("Add any comments about this
addition below. (can be blank)", "Comment")
strSQL = "INSERT INTO tblInstallation OrInUse " & _
"(relEquipmentI D, relInstrumentID , CurrentlyInstal led,
Comments, DateInstalled, Location)" & _
" VALUES " & _
"(" & Forms!frminstal l.EquipmentID & ", " &
Me.InstrumentID & ", Yes, '" & strComments & _
"', #" & datDate & "#, '" & strLocation & _
"')"
Debug.Print strSQL
DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
DoCmd.SetWarnin gs True

Works fine... Until someone decides to use a ", ', comma, or other
nasty punctuation in my comment box. Then it hoses my SQL statement
because it's just a simple text concatenation.

So....
- Scrub/wrap my comment somehow?
OR
- Just get over myself and use a recordset like a grownup Access
user...

Thanks,

Jon

Jan 30 '07 #1
2 2796
A comma shouln't be a problem, neither should a " as you are string
delimiting using ' .

To stop an ' embedded in the string being a problem simply double it up.

strComments = InputBox( _
"Add any comments about this addition below. (can be blank)", _
"Comment")

strComments = Replace(strComm ents , "'", "''",compare:=v bTextCompare)

' Rest of your code

Notes
"'" is a ' with a " either side
"''" is 2 ' with a " either side

--

Terry Kreft
"jonceramic " <jo********@gma il.comwrote in message
news:11******** **************@ a34g2000cwb.goo glegroups.com.. .
Hi,

Question... Is there any way to put a wrapper on a raw string going
through SQL, or should I bite the bullet and use a recordset method
instead?

Situation:
I'm trying to have the user add comment data to a table. I calculate
and/or determine all of the variables except for that comment.

So, currently, I'm using an inputbox to grab a string, and then using
that string as part of an INSERT INTO SQL command...

strComments = InputBox("Add any comments about this
addition below. (can be blank)", "Comment")
strSQL = "INSERT INTO tblInstallation OrInUse " & _
"(relEquipmentI D, relInstrumentID , CurrentlyInstal led,
Comments, DateInstalled, Location)" & _
" VALUES " & _
"(" & Forms!frminstal l.EquipmentID & ", " &
Me.InstrumentID & ", Yes, '" & strComments & _
"', #" & datDate & "#, '" & strLocation & _
"')"
Debug.Print strSQL
DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
DoCmd.SetWarnin gs True

Works fine... Until someone decides to use a ", ', comma, or other
nasty punctuation in my comment box. Then it hoses my SQL statement
because it's just a simple text concatenation.

So....
- Scrub/wrap my comment somehow?
OR
- Just get over myself and use a recordset like a grownup Access
user...

Thanks,

Jon

Jan 31 '07 #2
Yep, that's it. The replace method with two single quotes worked.
Thanks.

The reason the commas and " (double quotes) were issues was because of
how I was testing. If you have a ' (single quote) that causes the
initial problem, subsequent commas and double quotes _are_ parsed.

By eliminating the original problem of the single quote using the
"replace" method, then the comma and double quotes don't have chance
to be a problem.

Thanks Terry,

Jon

On Jan 31, 9:09 am, "Terry Kreft" <terry.kr...@mp s.co.ukwrote:
A comma shouln't be a problem, neither should a " as you are string
delimiting using ' .

To stop an ' embedded in the string being a problem simply double it up.

strComments = InputBox( _
"Add any comments about this addition below. (can be blank)", _
"Comment")

strComments = Replace(strComm ents , "'", "''",compare:=v bTextCompare)

' Rest of your code

Notes
"'" is a ' with a " either side
"''" is 2 ' with a " either side

--

Terry Kreft

"jonceramic " <joncera...@gma il.comwrote in message

news:11******** **************@ a34g2000cwb.goo glegroups.com.. .
Hi,
Question... Is there any way to put a wrapper on a raw string going
through SQL, or should I bite the bullet and use a recordset method
instead?
Situation:
I'm trying to have the user add comment data to a table. I calculate
and/or determine all of the variables except for that comment.
So, currently, I'm using an inputbox to grab a string, and then using
that string as part of an INSERT INTO SQL command...
strComments = InputBox("Add any comments about this
addition below. (can be blank)", "Comment")
strSQL = "INSERT INTO tblInstallation OrInUse " & _
"(relEquipmentI D, relInstrumentID , CurrentlyInstal led,
Comments, DateInstalled, Location)" & _
" VALUES " & _
"(" & Forms!frminstal l.EquipmentID & ", " &
Me.InstrumentID & ", Yes, '" & strComments & _
"', #" & datDate & "#, '" & strLocation & _
"')"
Debug.Print strSQL
DoCmd.SetWarnin gs False
DoCmd.RunSQL strSQL
DoCmd.SetWarnin gs True
Works fine... Until someone decides to use a ", ', comma, or other
nasty punctuation in my comment box. Then it hoses my SQL statement
because it's just a simple text concatenation.
So....
- Scrub/wrap my comment somehow?
OR
- Just get over myself and use a recordset like a grownup Access
user...
Thanks,
Jon- Hide quoted text -

- Show quoted text -

Jan 31 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17662
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
0
1910
by: Roy Smith | last post by:
I had a class called rule and a subclass of rule, called bgpRule, in a file called bgp.py. I decided to move the rule class to its own file, called rule.py. The original file did "import rule". I forgot to change bgpRule's __init__() method from calling rule.__init__() to call rule.rule.__init__(). Amazingly, this caused no immediate...
19
10566
by: les_ander | last post by:
Hi, suppose I am reading lines from a file or stdin. I want to just "peek" in to the next line, and if it starts with a special character I want to break out of a for loop, other wise I want to do readline(). Is there a way to do this? for example: while 1: line=stdin.peek_nextline()
1
1257
by: David A Barajas | last post by:
Is is possible to launch an Access Application within another app, creating a Parent/Child relationship between the App/Access? I'm trying to create a system where I can distribute the Access app without having to worry about Access runtime issues at the client site. I'm already working on porting the app to VB but would like to explore...
5
43187
by: meenasamy | last post by:
Hi all i have used a script that i downloaded and uses the fopen($url,'r'); function to access a url to retrieve data and i get this error Fatal error: fopen(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? i checked the 'allow_url_fopen = On' in php.ini and it is set to On, and still it...
0
2666
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is...
0
918
by: Charlie Miller | last post by:
Hi. I've run into a very strange problem with Python on the mac. I'm trying to write a python script which will monitor an application for exceptions. It turns out on a mac, to do this you want to use the Mach IPC interface, see: http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/...
2
2002
by: Peter Laman | last post by:
In my app I need to dynamically generate a series hyperlinks. Each hyperlink's action must be to focus a field in a <form>. I created the following function to create such a link (the argument is a field object, e.g. <input>): function createFieldAnchor(field, linkText) { var anchor = document.createElement("a"); anchor.field = field;...
0
2397
by: Peter Frost | last post by:
We're running PHP4.3 on a Solaris 9 box. PHP was compiled with the following option: '--with-openssl=/usr/local/ssl' phpinfo() suggests that openssl is enabled. However, when we try to use fopen with an https:// URL we receive the following message: PHP Notice: fopen(): Unable to find the wrapper &quot;https&quot; - did you forget to enable it...
0
8199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8336
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6606
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5389
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1447
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.