Results 1 to 2 of 2
  1. #1
    HS_1 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2016
    Posts
    118

    vba update code error.

    I am stuck with this for 2 days now and can't figure out what is wrong with my code. I am getting and error "Too Few Parameters. Expected 1."
    What I am trying to do is to run update quary based on textbox value on a form.



    Code:
    Private Sub btnClearLdtFlag_Click()
    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim strsql As String
    Set db = CurrentDb
    strsql = "UPDATE T_tblLDT INNER JOIN tbl_Tracking ON T_tblLDT.LineNo = tbl_Tracking.P_Line_No SET tbl_Tracking.LDT_Rev = [T_tblLDT].[Rev], tbl_Tracking.LDT_Unit = [T_tblLDT].[Unit], " & _
    "tbl_Tracking.LDT_Fluid_Code = [T_tblLDT].[FluidCode], tbl_Tracking.LDT_System = [T_tblLDT].[SystemNo], tbl_Tracking.LDT_Seq_No = [T_tblLDT].[SeqNo], " & _
    "tbl_Tracking.LDT_Size = [T_tblLDT].[LineSize], tbl_Tracking.LDT_Class = [T_tblLDT].[LineClass], tbl_Tracking.LDT_Insul_Type = [T_tblLDT].[InsulType], " & _
    "tbl_Tracking.LDT_Insul_Thk = [T_tblLDT].[InulThk], tbl_Tracking.LDT_Insul_Material = [T_tblLDT].[InsulMaterial], tbl_Tracking.LDT_Trace_Type = [T_tblLDT].[TraceType], " & _
    "tbl_Tracking.LDT_Hold_Temp = [T_tblLDT].[HoldTemp], tbl_Tracking.LDT_Oper_Temp = [T_tblLDT].[NormalOperTemp], tbl_Tracking.LDT_Upset_Temp = [T_tblLDT].[UpsetTemp], " & _
    "tbl_Tracking.LDT_Design_Temp = [T_tblLDT].[DesignTemp], tbl_Tracking.LDT_Design_Press = [T_tblLDT].[DesignPress], tbl_Tracking.EHT_LDT_Change = 'N' " & _
    "WHERE (((tbl_Tracking.LDT_Line_No) = Forms!frmLdtTrackingCompare![txtLineNo]));"
    'Set rst = db.OpenRecordSet(strsql, dbOpenDynaset)
    CurrentDb.Execute (strsql)
    End Sub

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    This error can have a few causes, one the most common one being that a form and/or control reference is mis-spelled. Another is that in vba a form/control reference must be concatenated, otherwise it is interpreted as a literal string instead of being evaluated as you exect:
    WHERE (((tbl_Tracking.LDT_Line_No) = " & Forms!frmLdtTrackingCompare![txtLineNo] & "));"

    Even if you concatenate, a form isn't explicitly visible within a sql statement being constructed in vba. The solution for that is to assign the reference to a variable and pass the variable instead, or a more complex approach is to Dim DAO.Parameters and assign the references to them.
    Last edited by Micron; 05-02-2019 at 04:47 PM. Reason: added info
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. UPDATE 3073 error trying to update a table field
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 10-11-2018, 05:11 PM
  2. Replies: 0
    Last Post: 10-10-2018, 12:28 PM
  3. Replies: 3
    Last Post: 05-10-2018, 07:48 AM
  4. update VBA 2.0 code in forms into access 7.0 code
    By toughwg in forum Programming
    Replies: 1
    Last Post: 12-08-2015, 11:40 AM
  5. Replies: 2
    Last Post: 06-28-2013, 12:58 PM

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