Why do I get an Syntaax error for insert into Statement .

I am using VB and MS access... If I run the query below without inserting the value for teh FOR column everything is fine..But once i include the FOR colum and  insert the strFor it throws an error.

Now the Delivery Date which is a string is also a cell above teh FOR in teh spreadsheet   . It is represented as strDDate. That is inserting fine. Why this problem only for this  For cell. I checked almost everything.

When I run this query in immediate window and cut and paste the same query in MS access it runs fine again.. Can you please help me ....
I also checked inserting every value ..It has nothing to do with the date or anything. there is only problenm in the for.
Also in MS access backend i made the field as memo , text . Still the problem

Dim strFor as String
strFor = Trim(App.Cells(ireqRow + 1, 3))
strDDate = Trim(App.Cells(ipodRow + 1, 3))

    ssql = ssql & Replace$(strPOrder, "'", "''") & "',#" & Format(dPODate, "dd-MMM-yy") & "#,"
    ssql = ssql & lFromId & "," & lToId & ",'" & Replace$(strDDate, "'", "''") & "','" & Replace$(strASFD, "'", "''") & "','"
    ssql = ssql & Replace$(strShipVia, "'", "''") & "','" & Replace$(strTerms, "'", "''") & "','" & Replace$(strRequestor, "'", "''")   & "','"
    ssql = ssql & Replace$(strBuyer, "'", "''") & "','" & Replace$(strFor, "'", "''") & "','" & Replace$(strQuoteNo, "'", "''") & "','" & Replace$(strReqNo, "'", "''") & "',"
    ssql = ssql & dblSubTotal & "," & dblShipAndHand & "," & dblSalesTax & "," & dblDiscount & ","
    ssql = ssql & dblDelAndInstall & "," & dblTotal & ")"

' This is what teh sql statement loosk in immediate window'. I have run this is access and it inserts fine.but from teh front end when i insert
i get the error of Syntax error of insert into statement ...'Conference rooms' corresponding to FOR is teh problem...
I am reading data from various excel seets and outting it into MS access ..eveything throws an error when inserting teh FOR value

insert into PURCHASE(PORDER,PODATE,SHIP_FROM,SHIP_TO,DDATE,ALL_SHIP_FOB_DEST,SHIP_VIA,TERMS, REQUESTOR,BUYER,FOR,QUOTE_NO,REQUISITION_NO,SUB_TOTAL,SHIP_HAND,SALES_TAX, DISCOUNT,DELIVERY_INSTALL,TOTAL) VALUES('7103',#16-Jan-04#,101,202,'ASAP','Prepay & Add', 'Next Day','Net 30','Michael Lewis','JK','Conference Rooms','134278059','7710',6927.8,60,419.27,0,0,7407.07)
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.

try enclosing FOR with brackets []. it might be a reserved word




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
Have you tried inserting the strFor, without using Trim function, since as far as i get it, you are replacing "'" with space anyway, try inserting it without using the Trim statement.
is the "for" column a character-type column?
Ryan ChongCommented:
>>strFor = Trim(App.Cells(ireqRow + 1, 3))
will error if App.Cells(ireqRow + 1, 3) contains null value, but seems it's from Excel, so if you like for 'safety' you can try like:
strFor = Trim("" & App.Cells(ireqRow + 1, 3))

btw, PePi got a nice catch there, and make sure all your fields data type are correct, as well as the sql statement
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
Visual Basic Classic

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.