Hi all,
I have the following code for adding multiple records in a table (Tbl1), selecting by a form listbox (list0) and works fine:
List2 is another listbox linking with a query showing the added records, the DatePar is a dete format field and the List1 is a listbox for adding quantity.
So...I made the following code to delete records:
Also this code works fine but when I change the SQL so delete selected records by a specific date defined from date form field (ParDate) I receive an error message (the DB can't find the field "|" etc). The code change is:
I think that the problem is on SQL syntax, or the date format, or something like that. I would like to inform you that the date format is a short date as dd/mm/yyyy. I can't find a solution. Any help is appreciated.
Thank you in advance.
I have the following code for adding multiple records in a table (Tbl1), selecting by a form listbox (list0) and works fine:
Code:
Private Sub BtnAddRec_Click()
Dim rst As DAO.Recordset
Dim VItm As Variant
For Each VItm In Me!List0.ItemsSelected
Set rst = CurrentDb.OpenRecordset("Tbl1", dbOpenDynaset)
rst.AddNew
rst.Fields("DatePar") = Me.ParDate
rst.Fields("ID1") = Me.List0.ItemData(VItm)
rst.Fields("Tem") = Me.List1
rst.Update
Me.List0.SetFocus
Me.List2.Requery
Next
End Sub
So...I made the following code to delete records:
Code:
Private Sub BtnDelRec_Click()
Dim vItem As Variant
For Each vItem In Me!List0.ItemsSelected
DoCmd.RunSQL "Delete from Tbl2 Where ID1= " & Me.List0.ItemData(vItem)
Next
Me.List0.Requery
Me.List2.Requery
End Sub
Code:
DoCmd.RunSQL "Delete from Tbl2 Where ID1= " & Me.List0.ItemData(vItem) And DatePar= " & Me.ParDate"
Thank you in advance.