Syntax error in insert into statement

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
LVL 1
perennialAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perkcCommented:
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
perkcCommented:
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
perennialAuthor Commented:
It seems working but, it's not appending to my other table "tblScoutRpt".
0
perkcCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GRayLCommented:
The second field of the insert clause is pID but the second field of the select clause is  APpID.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.