bryanchow1
New member
- Local time
- Tomorrow, 06:12
- Joined
- Feb 3, 2013
- Messages
- 7
Hello, i'm pretty new to access and vba and i cant seem to get my code to work. The code is meant to delete a specific (r) number of rows from a table. Rows are deleted based on a criteria if the item id entered in a text box matches the item id in a field in the table. (there are many records with the same item id in the table)
txtbox1 = the text box where the item id is entered.
txtbox2 = the tex tbox where r is entered.
Any help would be much appreciated.
Code:
Private Sub button2_Click()
Dim rs As dao.Recordset, i As Integer, r As Integer
On Error GoTo HandleError
r = Me.txtbox2 - 1
Set rs = CurrentDb.OpenRecordset("table 2", dbOpenDynaset)
With rs
For i = 1 To r
.Edit
If [Product ID] = Me.txtbox1 Then entirerow.Delete
.Update
Next i
End With
rs.Close
Set rs = Nothing
ExitHere:
Exit Sub
HandleError:
MsgBox Err.Description
Resume ExitHere
End Sub
txtbox1 = the text box where the item id is entered.
txtbox2 = the tex tbox where r is entered.
Any help would be much appreciated.