Results 1 to 15 of 15
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Syntax Error...missing operator

    I have a piece of code that stores a selection a user makes in a sub form. Code is below for reference. Whenever a user selects option 9 It throws the error message

    "Run-time error '3075':
    Syntax error (missing operator) in query expression "data stored in varReason is displayed here".

    What am I doing wrong?!?!??! If they select any other reason it works just fine. Thanks for your help in advance.

    Code:
    Dim varFormReason
    Dim varReason As String
    Dim varDenSelect
    Dim varOfferID
    Dim varDocDesc
    Dim varDenFrameValue
    Dim mySQL
    Dim varOfferIDCheck
    Dim db   As DAO.Database
    Dim rst As DAO.Recordset
    varDenFrameValue = Abs(Me.frameDenialOptions.Value)
        If varDenFrameValue = 0 Then
            MsgBox "Must select reason before saving.", vbOKOnly
            Exit Sub
        End If
        If varDenFrameValue = 1 Then
            varReason = Form_SfrmDenialReason.lblReason_1.Caption
        End If
        If varDenFrameValue = 2 Then
            varReason = Form_SfrmDenialReason.lblReason_2.Caption
        End If
        If varDenFrameValue = 3 Then
            varReason = Form_SfrmDenialReason.lblReason_3.Caption
        End If
        If varDenFrameValue = 4 Then
            varReason = Form_SfrmDenialReason.lblReason_4.Caption
        End If
        If varDenFrameValue = 5 Then
            varReason = Form_SfrmDenialReason.lblReason_5.Caption
        End If
        If varDenFrameValue = 6 Then
            varReason = Form_SfrmDenialReason.lblReason_6.Caption
        End If
        If varDenFrameValue = 7 Then
            varReason = Form_SfrmDenialReason.lblReason_7.Caption
        End If
        If varDenFrameValue = 8 Then
            varReason = Form_SfrmDenialReason.lblReason_8.Caption
        End If
        If varDenFrameValue = 9 Then
    '        Forms![frmNON-CORPOfferInformation].Requery
            varReason = Forms![frmNON-CORPOfferInformation].DenReason.Value
            RunCommand acCmdSaveRecord
        End If
        
        DoCmd.SetWarnings False
        Set db = Access.Application.CurrentDb
        Set rst = db.OpenRecordset("DenialReason")
        varDenSelect = frameDenialOptions.Value
        varOfferID = Forms![frmNON-CORPOfferInformation].OfferID.Value
        
        varDocDesc = "QryDelDenialReason"
        DoCmd.OpenQuery varDocDesc, acViewNormal
        mySQL = "INSERT INTO DenialReason (OfferID, DenialReason, DenSelect) VALUES ('" & varOfferID & "','" & varReason & "', '" & varDenSelect & "')"
        CurrentDb.Execute mySQL, dbFailOnError
    '    MsgBox "Denial Reason Saved.", vbOKOnly
        DoCmd.SetWarnings True


  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702
    Try removing the .Value part.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does varReason contain at that point (specifically)?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Remove the line "DoCmd.SetWarnings False". It's not needed.

    Is the form "Forms![frmNON-CORPOfferInformation]" open??

    You need to (should) comment your code.......

    Why do you have this line: DoCmd.OpenQuery varDocDesc, acViewNormal ?

    Put a breakpoint at the beginning of the code and single step thru the code. What line does the error occur???



    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  5. #5
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    The error always occurs on the:

    Code:
    CurrentDb.Execute mySQL, dbFailOnError
    after

    Code:
        mySQL = "INSERT INTO DenialReason (OfferID, DenialReason, DenSelect) VALUES ('" & varOfferID & "','" & varReason & "', '" & varDenSelect & "')"
    I just figured out the issue....what had happened is this.

    The text in the Forms![frmNON-CORPOfferInformation].DenReason.Value had a " ' " in it (Customer's). How can I get around this? The user needs to be able to use the " ' " in the text box.

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if the use can use ', then you can not use it. use "" instead.

  7. #7
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Unfortunately that did not work. When I tried to use Customer"'"s it gave me the same syntax error message. I guess I'll just have to live without it...

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I mean you don't use ' in you code. do not need to change the user data/value

  9. #9
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Forgive me but I'm not quite sure I follow. Are you referring to this piece of code?:

    Code:
    mySQL = "INSERT INTO DenialReason (OfferID, DenialReason, DenSelect) VALUES ('" & varOfferID & "','" & varReason & "', '" & varDenSelect & "')"
    What would I use instead of the ' in this part of the code?

  10. #10
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    mySQL = "INSERT INTO DenialReason (OfferID, DenialReason, DenSelect)
    VALUES (""" & varOfferID & """,""" & varReason & """, """ & varDenSelect & """)"

  11. #11
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    That worked. Thank you. Can you explain the difference in the two pieces? ( '" & variable & "' AND """ & variable & """).

  12. #12
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if you use ', and there is ' in the user data, Access may confuse and say syntax error.

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You might find this useful in explaining that problem as well as others:

    http://www.baldyweb.com/BuildSQL.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Thank you. Website is very helpful.

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Syntax error
    By smikkelsen in forum Access
    Replies: 6
    Last Post: 04-28-2010, 09:38 AM
  2. Error 3075 Missing Operator
    By KLynch0803 in forum Queries
    Replies: 5
    Last Post: 02-11-2010, 01:13 PM
  3. Syntax Error
    By KLynch0803 in forum Programming
    Replies: 11
    Last Post: 02-04-2010, 01:45 AM
  4. Replies: 1
    Last Post: 10-07-2009, 07:36 AM
  5. Missing Operator error
    By data123 in forum Forms
    Replies: 1
    Last Post: 03-15-2009, 04:34 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums