0

I am going to VBA for deleting data table.

It shows the errors shown in the screenshot.

Please help me to resolve it.

Private Sub cmdxoa_Click()
    If Not (Me.frmformsub1.Form.Recordset.EOF And Me.frmformsub1.Form.Recordset.BOF) Then
        If MsgBox("Do you wwant to delete ?", vbYesNo) = vbYes Then
            CurrentDb.Execute "DELETE from db " & _
                " where NOLC = " & Me.frmformsub1.Form.Recordset.Fields("nolc")
            Me.frmformsub1.Form.Requery
        End If
    End If
End Sub

theme css errror here

Erik A
  • 31,639
  • 12
  • 42
  • 67

1 Answers1

1

So if NOLC in the table is of type text, your criteria expression has to be:

"where NOLC = '" & Me.frmformsub1.Form.Recordset.Fields("nolc").Value & "'"

As you see you have to surround the value with '.

Remark: .Value isn't necessary, but it enhances the readability and assures that you are interested in the value and not in the object itself (the control in that case).

BUT: You should use parametrized queries instead string concatenation to avoid SQL injection:

How do I use parameters in VBA in the different contexts in Microsoft Access?

AHeyne
  • 3,377
  • 2
  • 11
  • 16
  • Thanks ! It is working now. I have another question need to resolve. I edited my question in this. Please help me to resolve it. Thanks – Minh Nguyễn Hà Dec 21 '18 at 00:01
  • This tears the context apart of my answer. You should undo your edit and open another question. – AHeyne Dec 21 '18 at 12:39