PC Review


Reply
Thread Tools Rate Thread

Compile Errors

 
 
NEWER USER
Guest
Posts: n/a
 
      26th Feb 2010
I have some SQL lines of code that fail in vb but work in SQL View Query.
Failing at the quotations.

DoCmd.RunSQL "UPDATE [Update Template] SET [Update Template].F11 =
Mid([F10],4,InStr([F10]," ")-1) " & _ 'it fails @ ")-1)"
WHERE (((InStr([F10],"/"))=0))" 'Possibly here too "/"


DoCmd.RunSQL "UPDATE tblSales SET tblSales.[Part Number] =
Replace(Replace([Part Number],"-",""),".","")" 'it fails "-"."")

How do I correct? Any help appreciated.



 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      26th Feb 2010
Double up the quotes when you want a single quote in the resulting string.

Dim strSQL as String
strSQL = "UPDATE [Update Template] " & _
" SET [Update Template].F11 = Mid([F10],4,InStr([F10],"" "")-1) " & _
" WHERE (((InStr([F10],""/""))=0))"

strSQL = "UPDATE tblSales " & +
"SET tblSales.[Part Number] = " & _
"Replace(Replace([Part Number],""-"",""""),""."","""")"

I almost always assign my query string to a variable. That way I can use
Debug.print strSQL
and examine the resulting string for errors. Once I am satisfied that I am
generating a valid SQL string then I can comment out the Debug.Print.

This might help:
Copy SQL statement from query to VBA
at:
http://allenbrowne.com/ser-71.html

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

NEWER USER wrote:
> I have some SQL lines of code that fail in vb but work in SQL View Query.
> Failing at the quotations.
>
> DoCmd.RunSQL "UPDATE [Update Template] SET [Update Template].F11 =
> Mid([F10],4,InStr([F10]," ")-1) " & _ 'it fails @ ")-1)"
> WHERE (((InStr([F10],"/"))=0))" 'Possibly here too "/"
>
>
> DoCmd.RunSQL "UPDATE tblSales SET tblSales.[Part Number] =
> Replace(Replace([Part Number],"-",""),".","")" 'it fails "-"."")
>
> How do I correct? Any help appreciated.
>
>
>

 
Reply With Quote
 
Daryl S
Guest
Posts: n/a
 
      26th Feb 2010
Newer User -

You need the text delimeter (quote), and to put any calculation outside of
quotes. Try this:

DoCmd.RunSQL "UPDATE [Update Template] SET [Update Template].F11 = '" &
Mid([F10],4,InStr([F10]," ")-1) & "'" & _
WHERE (((InStr([F10],"/"))='0'))"

DoCmd.RunSQL "UPDATE tblSales SET tblSales.[Part Number] = '" & _
Replace(Replace([Part Number],"-",""),".","") & "'"

A good way to work through these problems is to create a string variable
that you build the query in (e.g. Dim strSQL). Then you can add a debug
step in your code to see what you have built before trying to run the SQL.
Like this:

Dim strSQL as String
strSQL = "UPDATE tblSales SET tblSales.[Part Number] = '" & _
Replace(Replace([Part Number],"-",""),".","") & "'"

debug.print strSQL

DoCmd.RunSQL strSQL

--
Daryl S


"NEWER USER" wrote:

> I have some SQL lines of code that fail in vb but work in SQL View Query.
> Failing at the quotations.
>
> DoCmd.RunSQL "UPDATE [Update Template] SET [Update Template].F11 =
> Mid([F10],4,InStr([F10]," ")-1) " & _ 'it fails @ ")-1)"
> WHERE (((InStr([F10],"/"))=0))" 'Possibly here too "/"
>
>
> DoCmd.RunSQL "UPDATE tblSales SET tblSales.[Part Number] =
> Replace(Replace([Part Number],"-",""),".","")" 'it fails "-"."")
>
> How do I correct? Any help appreciated.
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
compile errors Gerhard Microsoft ASP .NET 6 24th Sep 2009 04:22 PM
Compile Errors : Me ? =?Utf-8?B?TWF1cmljaW8gU2lsdmE=?= Microsoft Access 0 2nd May 2005 07:41 PM
No errors but did not compile =?Utf-8?B?U2NvdHRE?= Microsoft Dot NET Compact Framework 4 14th Jan 2005 04:43 AM
compile errors? Victoria Microsoft Access VBA Modules 0 29th Jun 2004 03:57 PM
compile errors? Victoria Microsoft Access VBA Modules 0 29th Jun 2004 03:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:58 PM.