Results 1 to 7 of 7
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Syntax Error (Missing Operator) In Qry Expression 'Service Fee"

    Hi all,
    I am getting an error in my code (See Below)


    I am sure its in the " & CboDescription.Column(1) & " and I cannot figure out what syntax is needed.
    Its a combo box that I am trying to get the column 1 text from to post in the Description of my table which is short text

    Code:
    Private Sub CmdPostToLedger_Click()
        Dim strSQL As String
        Dim db As DAO.Database
        Set db = CurrentDb
        
    
    
    Select Case Me.CboCorrectionType
    
    
    Case 2 'Debit
    
    
            strSQL = "INSERT INTO tblAccountLedger (TransactionID, TransTypeID, TransCode, TransDate, AccountID, Description, TransMethodID, Debit) " & _
                "VALUES (" & TransactionID & ", " & CboTransType & ", '" & TransCode & "', #" & TransDate & "#, " & CboToAccount & ", " & CboDescription.Column(1) & ", " & CboTransMethod & ", " & TransAmount & ")"
    Case Else 'Credit
            strSQL = "INSERT INTO tblAccountLedger (TransactionID, TransTypeID, TransCode, TransDate, AccountID, Description, TransMethodID, Credit) " & _
                "VALUES (" & TransactionID & ", " & CboTransType & ", '" & TransCode & "', #" & TransDate & "#, " & CboToAccount & ", " & CboDescription.Column(1) & ", " & CboTransMethod & ", " & TransAmount & ")"
            End Select
            db.Execute strSQL, dbFailOnError
    
    
    Set db = Nothing
        Me.RecordLock = True
        Call Form_Current
        
        End Sub

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Pretty sure you cannot directly get a column value in sql by referencing it - not even if you include the form name. However, you can if you wrap the reference in Eval function but not sure I recall the syntax correctly. Try

    Eval(frmFormName.CboDescription.Column(1))
    and if not, perhaps

    Eval(Forms!frmFormName.CboDescription.Column(1))
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Assuming it's text you need to escape it?

    Code:
    " & CboToAccount & ", " & CboDescription.Column(1) & ", 
    
    " & CboToAccount & ", '" & CboDescription.Column(1) & "',
    @Micron you definitely can when you are simply creating a SQL string - it's evaluated in the concatenation.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  4. #4
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Please disregard as I found error... Needed ' and ' put on it.
    Sorry all,
    Thanks
    Dave

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    it's evaluated in the concatenation.
    Yes, course. My bad - had not finished one cup yet.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Quote Originally Posted by Micron View Post
    Yes, course. My bad - had not finished one cup yet.
    It's a bit later here, might be on my first shortly!
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    When are you going to start using Debug.Print?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 3
    Last Post: 11-07-2017, 06:26 PM
  2. Replies: 5
    Last Post: 10-25-2017, 01:47 PM
  3. Replies: 1
    Last Post: 06-02-2013, 04:34 AM
  4. Replies: 2
    Last Post: 03-08-2013, 12:59 PM
  5. Replies: 4
    Last Post: 07-25-2012, 04:01 AM

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