problemchild
New member
- Local time
- Today, 21:49
- Joined
- Feb 4, 2020
- Messages
- 1
Need Help having problem editing tables using my form... here is my codes and im using MS access 2013...and the table has auto number..i suspect that is the main error my codes doesnt or lacking something...plzz help ..newbie in access/vbs here..
Private Sub badd_Click()
If Me.txtname.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO Items(ItemName, Quantity, Expiration)" & _
"VALUES(" & Me.txtname & ",'" & Me.txtqty & "','" & Me.txtexp & "')"
Else
CurrentDb.Execute "UPDATE Items " & _
" SET ItemName=" & Me.txtname & _
", Quantity='" & Me.txtqty & "'" & _
", Expiration='" & Me.txtexp & "'" & _
" WHERE ItemName=" & Me.txtname.Tag
End If
bclear_Click
ItemSubForm.Form.Requery
End Sub
Private Sub bclear_Click()
Me.txtname = ""
Me.txtqty = ""
Me.txtexp = ""
Me.txtname.SetFocus
Me.bedit.Enabled = True
Me.badd.Caption = "Add"
Me.txtname.Tag = ""
End Sub
Private Sub bdelete_Click()
If Not (Me.ItemSubForm.Form.Recordset.EOF And Me.ItemSubForm.Form.Recordset.BOF) Then
If MsgBox("Are You Sure To Delete This Record?", vbYesNo) = vbYes Then
CurrentDb.Execute "DELETE FROM Items " & _
"WHERE ItemName=" & Me.ItemSubForm.Form.Recordset.Fields("Items")
Me.ItemSubForm.Form.Requery
End If
End If
End Sub
Private Sub bedit_Click()
If Not (Me.ItemSubForm.Form.Recordset.EOF And Me.ItemSubForm.Form.Recordset.BOF) Then
With Me.ItemSubForm.Form.Recordset
Me.txtname = .Fields("ItemName")
Me.txtqty = .Fields("Quantity")
Me.txtexp = .Fields("Expiration")
Me.txtname.Tag = .Fields("ItemName")
Me.badd.Caption = "Update"
Me.bedit.Enabled = False
End With
End If
Private Sub badd_Click()
If Me.txtname.Tag & "" = "" Then
CurrentDb.Execute "INSERT INTO Items(ItemName, Quantity, Expiration)" & _
"VALUES(" & Me.txtname & ",'" & Me.txtqty & "','" & Me.txtexp & "')"
Else
CurrentDb.Execute "UPDATE Items " & _
" SET ItemName=" & Me.txtname & _
", Quantity='" & Me.txtqty & "'" & _
", Expiration='" & Me.txtexp & "'" & _
" WHERE ItemName=" & Me.txtname.Tag
End If
bclear_Click
ItemSubForm.Form.Requery
End Sub
Private Sub bclear_Click()
Me.txtname = ""
Me.txtqty = ""
Me.txtexp = ""
Me.txtname.SetFocus
Me.bedit.Enabled = True
Me.badd.Caption = "Add"
Me.txtname.Tag = ""
End Sub
Private Sub bdelete_Click()
If Not (Me.ItemSubForm.Form.Recordset.EOF And Me.ItemSubForm.Form.Recordset.BOF) Then
If MsgBox("Are You Sure To Delete This Record?", vbYesNo) = vbYes Then
CurrentDb.Execute "DELETE FROM Items " & _
"WHERE ItemName=" & Me.ItemSubForm.Form.Recordset.Fields("Items")
Me.ItemSubForm.Form.Requery
End If
End If
End Sub
Private Sub bedit_Click()
If Not (Me.ItemSubForm.Form.Recordset.EOF And Me.ItemSubForm.Form.Recordset.BOF) Then
With Me.ItemSubForm.Form.Recordset
Me.txtname = .Fields("ItemName")
Me.txtqty = .Fields("Quantity")
Me.txtexp = .Fields("Expiration")
Me.txtname.Tag = .Fields("ItemName")
Me.badd.Caption = "Update"
Me.bedit.Enabled = False
End With
End If