Need someone else's eyes Update Statement Syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tasmontique
    New Member
    • Mar 2007
    • 20

    Need someone else's eyes Update Statement Syntax error

    Hello everyone,
    I keep getting a syntax error in my update statement. The only thing that I notice is
    that although the columns in my table have the same name as the fields on the form the compiler keeps changing the name eg

    strSQL = strSQL & "', Equipment='" & Me![equipment] (compiler format)

    should read
    strSQL = strSQL & "', Equipment='" & Me![Equipment].

    Also I am trying to format the where clause criteria with a combo box that has two columns. I am wondering if this is giving the error but the compiler does not highlight it.
    In the combo box's after update event this works fine

    Criteria = "[AirlineCode] &' '& [flightnuminout]" = " & [cboAdhoc]"

    rsCust.FindFirs t Criteria.

    However I am not sure how to concatenate two columns from the same table in the where clause.

    I think maybe

    1. 'strSQL = strSQL & " WHERE "[AirlineCode] &"' '"& [Flightnuminout]" = " & [cboAdhoc]"
    2.strSQL = strSQL & "' WHERE AirlineCode = '" & [cboAdhoc] & ""

    3. strSQL = strSQL & "' WHERE AirlineCode And Flightnuminout= '" & [cboAdhoc] & ""
  • pks00
    Recognized Expert Contributor
    • Oct 2006
    • 280

    #2
    Ok, first off, your first sql, did u end it with single quotes or forget to post that?
    i.e.
    strSQL = strSQL & "', Equipment='" & Me![Equipment].

    should be

    strSQL = strSQL & "', Equipment='" & Me![Equipment]. & "'"


    Secondly, what are you trying to achieve here

    strSQL = strSQL & "' WHERE AirlineCode And Flightnuminout= '" & [cboAdhoc] & ""

    Is cboAdhoc a combination of both ArlineCode and Flightnuminout concatenated? If so then try this

    strSQL = strSQL & "' WHERE AirlineCode & Flightnuminout= '" & [cboAdhoc] & ""

    how many columns in cboAdhoc, u couldbe looking at the wrong column
    to verify the value, type this in

    msgbox cboAdhoc

    Comment

    • tasmontique
      New Member
      • Mar 2007
      • 20

      #3
      Thanks for the sql syntax corrections.
      My combox is still giving me trouble

      The combobox consists of two columns. I search the records to edit with this combobox code

      Private Sub cboAdhoc_AfterU pdate()
      Dim d As DAO.Database
      Dim rsCust As DAO.Recordset
      Dim Criteria As String
      rsCus
      Set d = CurrentDb
      Set rsAdhoc = d.OpenRecordset ("tblflight1 ", dbOpenDynaset)
      'selects concatenated fields in access table
      Criteria = "[AirlineCode] &' '& [flightnuminout]" = " & [cboAdhoc]"

      rsAdhoc.FindFir st Criteria


      Me!Equipment = rsAdhoc("Equipm ent")
      Me!AirlineCode = rsAdhoc("Airlin eCode")
      Me!AirlineCode = UCase(Me!Airlin eCode)
      Me!Flightnumino ut = rsAdhoc("Flight numinout")

      This works fine. If this syntax is wrong please correct me.

      However in the update table statement I keep getting an error as if it is only recognizing the airlinecode and not the flightnuminout.

      When I click on the combobox it displays both columns airlinecode and flightnuminout.

      However after it is selected it displays only airlinecode.

      I wonder if the combobox can be read as an index eg in sql statement

      Where AirlineCode & Flightnuminout = & [cboAdhoc.Value( )]" would this allow it to read the two coulumns?
      When I try I get an error

      Comment

      • pks00
        Recognized Expert Contributor
        • Oct 2006
        • 280

        #4
        Originally posted by tasmontique
        When I click on the combobox it displays both columns airlinecode and flightnuminout.

        However after it is selected it displays only airlinecode.
        this means u have to reference them using column numbers

        try this

        strSQL = strSQL & "' WHERE AirlineCode = '" & cboAdhoc.Column (0) & ' AND Flightnuminout = '" & cboAdhoc.Column (1) & ""


        cboAdhoc.Column (0) returns value in 1st column
        cboAdhoc.Column (1) returns value in 2nd column
        etc

        If any fields are numeric then u drop the wrapping in single quotes

        Comment

        • tasmontique
          New Member
          • Mar 2007
          • 20

          #5
          Thank you so much this both values are being read in the update statement.

          However, the syntax error has come back. After I click the command button a message box from access comes up appearing as if it has passed all the values from the form to the table columns but then the update syntax error comes up again. Here is all my code.

          f IsNull(Me!Airli neCode) Then
          MsgBox "AirlineCod e is a Required Entry.", 48
          Me!AirlineCode. SetFocus
          Exit Sub
          End If

          If IsNull(Me!fligh tnuminout) Then
          MsgBox "Flightnumi nout is a Required Entry.", 48
          Me!flightnumino ut.SetFocus
          Exit Sub
          End If

          If IsNull(Me!cboAd hoc) Then
          MsgBox "Is this a new addition? If so, use the Add button below to save this record."
          Me!cmdAddRec0.S etFocus
          Exit Sub
          End If


          '**** Save Changes ****
          Dim db As Database
          Set db = CurrentDb
          Dim strSQL As String

          strSQL = "UPDATE tblflight1 "

          strSQL = strSQL & "',SET AirlineCode='" & Me![AirlineCode] & "'"
          strSQL = strSQL & "', Equipment='" & Me![Equipment] & "'"
          strSQL = strSQL & "', Flightnuminout= '" & Me![flightnuminout] & "'"
          strSQL = strSQL & "', AirlineName='" & Me![AirlineName] & "'"
          strSQL = strSQL & "', STA='" & Me![STA] & "'"
          strSQL = strSQL & "', STD='" & Me![STD] & "'"
          strSQL = strSQL & "',RouteTo= '" & Me![RouteTo] & "'"
          strSQL = strSQL & "',RouteFro m='" & Me![RouteFrom] & "'"
          strSQL = strSQL & "',Configuratio n='" & Me![Configuration] & "'"
          strSQL = strSQL & "',ProgramI N='" & Me![ProgramIN] & "'"
          strSQL = strSQL & "',ProgramOUT=' " & Me![ProgramOUT] & "'"
          strSQL = strSQL & "',Remarks= '" & Me![Remarks] & "'"
          strSQL = strSQL & "',Montharr ='" & Me![Montharr] & "'"
          strSQL = strSQL & "',Monthactivit y='" & Me![Monthactivity] & "'"
          strSQL = strSQL & "',Arrtime= '" & Me![arrtime] & "'"
          strSQL = strSQL & "',Deptime= '" & Me![deptime] & "'"
          strSQL = strSQL & "',Arrivaldate= '" & Me![Arrivaldate] & "'"
          strSQL = strSQL & "',Departuredat e='" & Me![Departuredate] & "'"
          strSQL = strSQL & "',WK1='" & Me![WK1] & "'"
          strSQL = strSQL & "',WK2='" & Me![WK2] & "'"
          strSQL = strSQL & "',WK3='" & Me![WK3] & "'"
          strSQL = strSQL & "',WK4='" & Me![WK4] & "'"



          strSQL = strSQL & " 'WHERE AirlineCode = '" & cboAdhoc.Column (0) & "' AND Flightnuminout = '" & cboAdhoc.Column (1) & ""
          MsgBox strSQL

          db.Execute strSQL

          MsgBox "Changes to " & Me!AirlineCode & " have been saved."

          '**** clear the controls to add more flights ****
          Call ClearControls

          Comment

          Working...