Search code examples
sqlvbams-access-2016

VBA/SQL issue access


I keep recieving compiling errors saying that txtlln in the where line cannot be found. I am fairly new to SQL/VBA so I am not sure I am using the correct expressions to have this work.

Private Sub btnlledit_Click()
Dim strSQL As String
SQL = "UPDATE tblll " & _
      "SET [Component/Product] = '" & Forms!frmaddll!txtllcomponent & "',[HN] = '" & Forms!frmaddll!txtllhn & "' " & _          
      "WHERE [LLN] = '" & Forms!frmaddll!txtlln.value & "';"
debug.print sql
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True
DoCmd.Requery

Me.Refresh 
End Sub

Solution

  • You seem to have a few issues swith your string concatenation.

    Private Sub btnlledit_Click()
        Dim strSQL As String
    
        SQL = "UPDATE tblll " & _
              "SET [Component/Product] = '" & Forms!frmaddll!txtllcomponent & "' " & _
              "WHERE [LLN] = '" & Forms!frmaddll!txtlln.value & "';"
        debug.print sql
        DoCmd.RunSQL strSQL
        DoCmd.SetWarnings True
        DoCmd.Requery
    
        Me.Refresh
    
    End Sub