Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Syntax error in insert into statement

Posted on 2004-10-27
5
Medium Priority
?
263 Views
Last Modified: 2008-03-10
I have the following sql, when I try to run it gave me "Syntax error in insert into statement.  

Could someone see if they could find the problem



dim fSql as string


    myDate = Nz(InputBox("Enter Date"), "")
    myRange = (InputBox("Enter Range No."))
   
       

fSql = " INSERT INTO tblScoutRpt ( DatProcess, pID, IMITEM, IMSIZE, GENUS, SPECIS, IMDES3 "
fSql = fSql & " LRCODE, LRCSRC, LRAREA, HOUSE, BENCH, SOWD, INVQ, QTOH, RED, RDYD, EXPD "
fSql = fSql & " MVDT, GrnHouseOwner, Cult1, CultSeverity1, CT1, Cult2, CultSeverity2, CT2 "
fSql = fSql & " Cult3, CultSeverity3, CT3, Cult4, CultSeverity4, CT4, Disease1 "
fSql = fSql & " DiseaseSeverity1, DT1, Disease2, DiseaseSeverity2, DT2, Disease3 "
fSql = fSql & " DiseaseSeverity3, DT3, Disease4, DiseaseSeverity4, DT4, Pest1, PestStage1 "
fSql = fSql & " PestSeverity1, PT1, Pest2, PestStage2, PestSeverity2, PT2, Pest3 "
fSql = fSql & " PestStage3, PestSeverity3, PT3, Pest4, PestStage4, PestSeverity4, PT4 "
fSql = fSql & " MisComment, PlantGSV, Range ) "
fSql = fSql & " SELECT ([#" & myDate & "#] AS DatProcess, [pID] & (Format([DatProcess],#mmddyy#)) AS APpID "
fSql = fSql & " tblScout.IMITEM , tblScout.IMSIZE, tblScout.Genus, tblScout.SPECIS "
fSql = fSql & " tblScout.IMDES3, tblScout.LRCODE, tblScout.LRCSRC, tblScout.lrarea "
fSql = fSql & " tblScout.House, tblScout.BENCH, tblScout.sowd, tblScout.INVQ, tblScout.QTOH "
fSql = fSql & " tblScout.RED, tblScout.RDYD, tblScout.EXPD, tblScout.MVDT "
fSql = fSql & " tblScout.GrnHouseOwner, tblScout.cult1, tblScout.CultSeverity1 "
fSql = fSql & " tblScout.CT1, tblScout.Cult2, tblScout.CultSeverity2, tblScout.CT2 "
fSql = fSql & " tblScout.Cult3, tblScout.CultSeverity3, tblScout.CT3, tblScout.Cult4 "
fSql = fSql & " tblScout.CultSeverity4, tblScout.CT4, tblScout.Disease1 "
fSql = fSql & " tblScout.DiseaseSeverity1, tblScout.DT1, tblScout.Disease2 "
fSql = fSql & " tblScout.DiseaseSeverity2, tblScout.DT2, tblScout.Disease3 "
fSql = fSql & " tblScout.DiseaseSeverity3, tblScout.DT3, tblScout.Disease4 "
fSql = fSql & " tblScout.DiseaseSeverity4, tblScout.DT4, tblScout.Pest1, tblScout.PestStage1 "
fSql = fSql & " tblScout.PestSeverity1, tblScout.PT1, tblScout.Pest2, tblScout.PestStage2 "
fSql = fSql & " tblScout.PestSeverity2, tblScout.PT2, tblScout.Pest3, tblScout.PestStage3 "
fSql = fSql & " tblScout.PestSeverity3, tblScout.PT3, tblScout.Pest4, tblScout.PestStage4 "
fSql = fSql & " tblScout.PestSeverity4, tblScout.PT4, tblScout.MisComment, tblScout.PlantGSV, [myRange] AS ApRange) "
fSql = fSql & " FROM tblScout "
fSql = fSql & " WHERE (((tblScout.Cult1) Is Not Null)) OR (((tblScout.Disease1) Is Not Null)) OR (((tblScout.Pest1) Is Not Null)) "
CurrentDb.Execute fSql

Thanks you

Perennial
0
Comment
Question by:perennial
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 10

Expert Comment

by:perkc
ID: 12426720
Your lines need ,'s:

fSql = " INSERT INTO tblScoutRpt ( DatProcess, pID, IMITEM, IMSIZE, GENUS, SPECIS, IMDES3 "
fSql = fSql & " LRCODE, LRCSRC, LRAREA, HOUSE, BENCH, SOWD, INVQ, QTOH, RED, RDYD, EXPD "

should be:

fSql = " INSERT INTO tblScoutRpt ( DatProcess, pID, IMITEM, IMSIZE, GENUS, SPECIS, IMDES3, "
fSql = fSql & " LRCODE, LRCSRC, LRAREA, HOUSE, BENCH, SOWD, INVQ, QTOH, RED, RDYD, EXPD, "

Repeat the comma's on all lines nessesary.

perkc
0
 
LVL 10

Expert Comment

by:perkc
ID: 12426738
The total fix would be:

fSql = " INSERT INTO tblScoutRpt ( DatProcess, pID, IMITEM, IMSIZE, GENUS, SPECIS, IMDES3, "
fSql = fSql & " LRCODE, LRCSRC, LRAREA, HOUSE, BENCH, SOWD, INVQ, QTOH, RED, RDYD, EXPD, "
fSql = fSql & " MVDT, GrnHouseOwner, Cult1, CultSeverity1, CT1, Cult2, CultSeverity2, CT2, "
fSql = fSql & " Cult3, CultSeverity3, CT3, Cult4, CultSeverity4, CT4, Disease1, "
fSql = fSql & " DiseaseSeverity1, DT1, Disease2, DiseaseSeverity2, DT2, Disease3, "
fSql = fSql & " DiseaseSeverity3, DT3, Disease4, DiseaseSeverity4, DT4, Pest1, PestStage1, "
fSql = fSql & " PestSeverity1, PT1, Pest2, PestStage2, PestSeverity2, PT2, Pest3, "
fSql = fSql & " PestStage3, PestSeverity3, PT3, Pest4, PestStage4, PestSeverity4, PT4, "
fSql = fSql & " MisComment, PlantGSV, Range ) "
fSql = fSql & " SELECT ([#" & myDate & "#] AS DatProcess, [pID] & (Format([DatProcess],#mmddyy#)) AS APpID, "
fSql = fSql & " tblScout.IMITEM , tblScout.IMSIZE, tblScout.Genus, tblScout.SPECIS, "
fSql = fSql & " tblScout.IMDES3, tblScout.LRCODE, tblScout.LRCSRC, tblScout.lrarea, "
fSql = fSql & " tblScout.House, tblScout.BENCH, tblScout.sowd, tblScout.INVQ, tblScout.QTOH, "
fSql = fSql & " tblScout.RED, tblScout.RDYD, tblScout.EXPD, tblScout.MVDT, "
fSql = fSql & " tblScout.GrnHouseOwner, tblScout.cult1, tblScout.CultSeverity1, "
fSql = fSql & " tblScout.CT1, tblScout.Cult2, tblScout.CultSeverity2, tblScout.CT2, "
fSql = fSql & " tblScout.Cult3, tblScout.CultSeverity3, tblScout.CT3, tblScout.Cult4, "
fSql = fSql & " tblScout.CultSeverity4, tblScout.CT4, tblScout.Disease1, "
fSql = fSql & " tblScout.DiseaseSeverity1, tblScout.DT1, tblScout.Disease2, "
fSql = fSql & " tblScout.DiseaseSeverity2, tblScout.DT2, tblScout.Disease3, "
fSql = fSql & " tblScout.DiseaseSeverity3, tblScout.DT3, tblScout.Disease4, "
fSql = fSql & " tblScout.DiseaseSeverity4, tblScout.DT4, tblScout.Pest1, tblScout.PestStage1, "
fSql = fSql & " tblScout.PestSeverity1, tblScout.PT1, tblScout.Pest2, tblScout.PestStage2, "
fSql = fSql & " tblScout.PestSeverity2, tblScout.PT2, tblScout.Pest3, tblScout.PestStage3, "
fSql = fSql & " tblScout.PestSeverity3, tblScout.PT3, tblScout.Pest4, tblScout.PestStage4, "
fSql = fSql & " tblScout.PestSeverity4, tblScout.PT4, tblScout.MisComment, tblScout.PlantGSV, [myRange] AS ApRange) "
fSql = fSql & " FROM tblScout "
fSql = fSql & " WHERE (((tblScout.Cult1) Is Not Null)) OR (((tblScout.Disease1) Is Not Null)) OR (((tblScout.Pest1) Is Not Null)) "


perkc
0
 
LVL 1

Author Comment

by:perennial
ID: 12426860
It seems working but, it's not appending to my other table "tblScoutRpt".
0
 
LVL 10

Accepted Solution

by:
perkc earned 2000 total points
ID: 12427021
Does the following sql return any records?

SELECT ([pID] & (Format([DatProcess],#mmddyy#)) AS APpID,
tblScout.IMITEM , tblScout.IMSIZE, tblScout.Genus, tblScout.SPECIS,
tblScout.IMDES3, tblScout.LRCODE, tblScout.LRCSRC, tblScout.lrarea,
tblScout.House, tblScout.BENCH, tblScout.sowd, tblScout.INVQ, tblScout.QTOH,
tblScout.RED, tblScout.RDYD, tblScout.EXPD, tblScout.MVDT,
tblScout.GrnHouseOwner, tblScout.cult1, tblScout.CultSeverity1,
tblScout.CT1, tblScout.Cult2, tblScout.CultSeverity2, tblScout.CT2,
tblScout.Cult3, tblScout.CultSeverity3, tblScout.CT3, tblScout.Cult4,
tblScout.CultSeverity4, tblScout.CT4, tblScout.Disease1,
tblScout.DiseaseSeverity1, tblScout.DT1, tblScout.Disease2,
tblScout.DiseaseSeverity2, tblScout.DT2, tblScout.Disease3,
tblScout.DiseaseSeverity3, tblScout.DT3, tblScout.Disease4,
tblScout.DiseaseSeverity4, tblScout.DT4, tblScout.Pest1, tblScout.PestStage1,
tblScout.PestSeverity1, tblScout.PT1, tblScout.Pest2, tblScout.PestStage2,
tblScout.PestSeverity2, tblScout.PT2, tblScout.Pest3, tblScout.PestStage3,
tblScout.PestSeverity3, tblScout.PT3, tblScout.Pest4, tblScout.PestStage4,
tblScout.PestSeverity4, tblScout.PT4, tblScout.MisComment, tblScout.PlantGSV, [myRange] AS ApRange)
FROM tblScout
WHERE (((tblScout.Cult1) Is Not Null)) OR (((tblScout.Disease1) Is Not Null)) OR (((tblScout.Pest1) Is Not Null))

I'm guessing that it doesn't. I think the problem is with the following line:

fSql = fSql & " SELECT ([#" & myDate & "#] AS DatProcess, [pID] & (Format([DatProcess],#mmddyy#)) AS APpID, "

Try:
fSql = fSql & " SELECT ([#" & myDate & "#] AS DatProcess, [pID] & (Format(#" & myDate & "#,#mmddyy#)) AS APpID, "

Also, where is the [pID] comming from? Is it a field in the tblScout table? a variable?

perkc

0
 
LVL 44

Expert Comment

by:GRayL
ID: 12427182
The second field of the insert clause is pID but the second field of the select clause is  APpID.  
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question