Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2013
    Posts
    22

    Question Unanswered: Trying to add and update records on one button to my subform

    Im trying to update my edit fields if I click the edit button it changes the Add caption to update so where ill have two adds where ill add my new fields and where ill update the existing fields everything is working im just trying to solve solution.
    I get this error: Run-time error '3134'.
    Syntax error in UPDATE statement.
    Thanks for helping me people appreciated aloth.

    Private Sub cmdAdd_Click()

    Dim strSQL As String

    If Me.txtTranID.Tag & "" = "" Then

    strSQL = "INSERT INTO PlantTransactionQuery (TransactionID, [PlantTransaction_Plant Number], Categories, Description, Location, [TransactionDate], Opening_Hours, Closing_Hours, [Hours Worked], Fuel, [Fuel Cons Fuel/Hours], [Hour Meter Replaced], Comments) "
    strSQL = strSQL & "VALUES (" & txtTranID & ", '" & txtPlantNo & "', '" & txtCategories & "', '" & txtDescription & "', '" & txtLocation & "', #" & txtTransDate & "#, " & txtOpenHrs & ", " & CloseHrs & ", " & txtHrsWorked & ", '" & txtFuel & "', " & txtFuelConsFuelHr & ", " & txtHrMtrRep & ", '" & txtComments & "');"
    CurrentDb.Execute strSQL
    Else
    strSQL = "UPDATE PlantTransactionQuery " & _
    "SET TransactionID=" & Me.txtTranID & _
    ",PlantTransaction_Plant Number='" & Me.txtPlantNo & "'" & _
    ",Categories='" & Me.txtCategories & "'" & _
    ",Description='" & Me.txtDescription & "'" & _
    ",Location='" & Me.txtLocation & "'" & _
    ",TransactionDate='" & Me.txtTransDate & "'" & _
    ",Opening_Hours='" & Me.txtOpenHrs & "'" & _
    ",Closing_Hours='" & Me.txtDescription & "'" & _
    ",Hours Worked='" & Me.txtDescription & "'" & _
    ",Fuel='" & Me.txtFuel & "'" & _
    ",Fuel Cons Fuel/Hours='" & Me.txtFuelConsFuelHr & "'" & _
    ",Hour Meter Replaced='" & Me.txtHrMtrRep & "'" & _
    ",Comments='" & Me.txtComments & "'" & _
    " WHERE TransactionID=" & Me.txtTranID.Tag
    CurrentDb.Execute strSQL
    End If
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    At first sight:
    Code:
    ",[Fuel Cons Fuel/Hours]='" & Me.txtFuelConsFuelHr & "'" & _
    ",[Hour Meter Replaced]='" & Me.txtHrMtrRep & "'" & _
    Column names containing spaces or non-alphanumeric characters (except the underscore) must be enclosed within square brackets.
    Have a nice day!

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
  •