Can't Edit/Add values in my Tables using form! (1 Viewer)

problemchild

New member
Local time
Tomorrow, 04:21
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
 

jdraw

Super Moderator
Staff member
Local time
Today, 16:21
Joined
Jan 23, 2006
Messages
15,383
A good debugging technique is to use a Debug.Print (yourSQL statement) to see how Access understands your SQL.
Just comment out your CurrentDb.Execute line and Debug.Print the appropriate SQL
Often better to assign your sql to a variable, then debug.print variablename .

Good luck.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:21
Joined
Aug 30, 2003
Messages
36,127
Here's a visual of what jdraw is suggesting:

 

Users who are viewing this thread

Top Bottom