473,326 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Delete Function

I'm reading Vb code of my ex-colleague and here is what I see
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE FROM tblA WHERE fieldA = """ & name & Chr(34)
  2. DoCmd.RunSQL strSQL, -1
My question is why this is working !!! isn't it lacking one double quotation?? there is one quotation before DELETE but there is no ending quotation!!
May 27 '10 #1
9 3913
debasisdas
8,127 Expert 4TB
Read again.
May 28 '10 #2
NeoPa
32,556 Expert Mod 16PB
Thanks for that helpful comment Debas :D

Chr(34) actually resolves to a double-quote character ("). So you see this is perfectly sensible SQL.

The VBA is pretty poor though. Whoever wrote it was either very sloppy or trying to show they were clever. If this code is in a production system anywhere though (as opposed to a class and designed to make the students think) then they've only shown the opposite.
May 28 '10 #3
NeoPa
32,556 Expert Mod 16PB
PS. A handy trick for seeing what a Chr() call resolves to is to hold the Alt key down while typing the number out on the numeric keypad. If you try this with 34 you'll see the result is ".
May 28 '10 #4
Thanks Neopa, I changed it to the following code, is that correct? it didn't throw any error message.
p.s: What kind of moderator is Debas!!! No one forced you to reply on the threads !
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE FROM tblA WHERE fieldA =" & Chr(34) & name & Chr(34)
  2. DoCmd.RunSQL strSQL, -1
May 28 '10 #5
Oh and thanks for the trick , it was really helpful.
May 28 '10 #6
colintis
255 100+
i think using Chr(34) would be preferred for easier reading of code, as using """ may sometime confuse about the quotes with a quick look through (e.g. Did i just see 5 quotes or 6? Did this part is including the double quotes to output?) . Anyway, it depends which method coder preferred, easy indicate or shorter coding. And using a unified standard of coding, as your ex-colleague's code was a bad example. (or as NeoPa said he was just showing off)
May 28 '10 #7
NeoPa
32,556 Expert Mod 16PB
I would take a different view (without arguing with Colintis. His view is equally valid. Just different from mine).

I never saw a good reason for using Chr(34) to create a string with quotes (') in. It is not easier to read unless you already use it and recognise it. I would say rather that it was harder to read as a form of translation is necessary, where it is not necessary for using the character natively. This is clearly demonstrated by the question being required in the first place. Quotes (') and double-quotes (") (See Quotes (') and Double-Quotes (") - Where and When to use them) are easily distinguished when used correctly, either in the code window or, when posting, in the code tags, and have the benefit of showing exactly what is expected and required in the string. Only proportional fonts make '' look like ".
Expand|Select|Wrap|Line Numbers
  1. Only proportional fonts make '' look like ".
I would write your code as :
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE FROM tblA WHERE fieldA ='" & Me.Name & "'"
  2. DoCmd.RunSQL strSQL, True
Jun 1 '10 #8
OldBirdman
675 512MB
All of the above is true. Different approaches and preferences.
If the value of Me.name contains a quote imbedded within it, all of the above will produce errors. If these are person's names, a single quote would be expected [James O'Reily]. Names of movies or music albums might contain either single or double quotes.
Expand|Select|Wrap|Line Numbers
  1. strSQL = "DELETE FROM tblA WHERE fieldA ='" & Me.Name & "'" 
This assigns to strSQL the string [DELETE FROM tblA WHERE fieldA ='James O'Reily']
Note: Square brackets [] are used to show actual text string to avoid confusing quotes.
Jun 1 '10 #9
NeoPa
32,556 Expert Mod 16PB
That's absolutely right OB. Further help with this can be found at SQL Injection Attack.
Jun 2 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
3
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. I am...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
6
by: Angus Comber | last post by:
I have been looking at the fopen etc but cannot seem to find a way to delete a file using C runtime functions. Angus Comber ac@NOSPAMiteloffice.com
4
by: kimimaro | last post by:
Thank you for your help I think I know what the problem is. Firstly the add_record cannot read the record.txt or something if the record.txt (in which I used it to store the details of each record)...
0
by: Rich | last post by:
I have a page that list all records in an access table. I would like to add a delete record function to the list to delete selected records. Here is my current code: ...
1
by: Patch | last post by:
Hello I need a function in a compiled DLL that I can call from VB that will delete all entries of a specified value from a large integer array. Or a function that will delete all characters...
1
by: =?gb2312?B?wNbA1rTzzOzKpg==?= | last post by:
struct elem { int a; int b; }; elem * p = new elem; delete p; //-----will the text above memory leak?
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
1
by: Vinodhg | last post by:
hello Sir, I am a beginner in PHP MYSQL I have created a table using MYSQL in PHP... In that table i have included checkbox in each row.. Now i want to delete some of the rows which i checked...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.