473,387 Members | 1,766 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,387 software developers and data experts.

vba code vs sql

232 100+
Expand|Select|Wrap|Line Numbers
  1. Debug.Print ("update TABLE set REM=REM & ' DB'  WHERE  ISDATE(Left(DOB,2) & " / " & Mid(DOB,3,2) & " / " & Mid(DOB,5,4)) = 0")
  2. CurrentDb.Execute ("update TABLE set REM=REM & ' DB'  WHERE  ISDATE(Left(DOB,2) & " / " & Mid(DOB,3,2) & " / " & Mid(DOB,5,4)) = 0")
  3.  
same query running very successfully in sql mode while giving type mismatch error in vba code in fact debug.print is also giving type mismatch error
Expand|Select|Wrap|Line Numbers
  1. update TABLE set REM=REM & ' DB'  WHERE  ISDATE(Left(DOB,2) & " / " & Mid(DOB,3,2) & " / " & Mid(DOB,5,4)) = 0
this query is running successfully
Kindly help
Feb 7 '14 #1
4 1117
MikeTheBike
639 Expert 512MB
Hi Try this
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "update TABLE set REM=REM & ' DB'  WHERE  ISDATE(Left(DOB,2) & "" / "" & Mid(DOB,3,2) & "" / "" & Mid(DOB,5,4)) = 0"
You need to double up the quote marks when constructing a string containing/include quotes.


HTH

MTB
Feb 7 '14 #2
NeoPa
32,556 Expert Mod 16PB
The more correct approach (when dealing with SQL strings specifically) is to use the correct SQL quotes as you have done in the first string (' DB').

Thus, it should be :
Expand|Select|Wrap|Line Numbers
  1. Dim strSQL As String
  2.  
  3. strSQL = "UPDATE [Table] " _
  4.        & "SET    [REM]=[REM] & ' DB' " _
  5.        & "WHERE  Not IsDate(Left([DOB],2)+'/'+Mid([DOB],3,2)+'/'+Mid([DOB],5,4))"
  6. Debug.Print strSQL
  7. Call CurrentDb().Execute(strSQL)
NB. Only use + for joining strings when none of the values is Null or when you want Null propagation. I use it here to keep the code shorter. "&" works perfectly well.
Feb 7 '14 #3
NeoPa
32,556 Expert Mod 16PB
To make things perfectly clear - MtB's approach will work, as Jet SQL will happily work with double-quotes in place of the correct SQL quotes (').

The approach indicated will also work in various other scenarios where quotes of either type need to be entered into a string which is, itself, delineated by those same quotes.

So, important and useful to understand, even if not my personal choice as an answer to this specific question.
Feb 7 '14 #4
zmbd
5,501 Expert Mod 4TB
Just some more food for thought: Quotes (') and Double-Quotes (") - Where and When to use them
Feb 7 '14 #5

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

Similar topics

51
by: Mudge | last post by:
Please, someone, tell me why OO in PHP is better than procedural.
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
0
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Today we are going to look at Code Access Security. Code access security is a feature of .NET that manages code depending on its trust level. If the CLS trusts the code enough to...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
4
by: KenFehling | last post by:
Hello. I am wondering if there exists a piece of software that takes multiple .js files that are nicely indented and commented and create one big tightly packed .js file. I'm hoping the one file...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
by: blackrosezy | last post by:
#include char *code; void main() { char buf = "book";
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
66
by: Jon Skeet [C# MVP] | last post by:
I'm sure the net will be buzzing with this news fairly soon, but just in case anyone hasn't seen it yet: Microsoft are going to make the source code for the .NET framework (parts of it,...
2
by: AccessCoder | last post by:
What is the proper way to reference code snippets that are copied from usenet group examples? What about when a developer posts code that is copyrighted and they allow you to use it in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.