Hello all and thanks in advance for any help you provide!Once again another bug came up. What the code does is depending what option the user checked update a certain table. The code i'm using is the following:
And the button click:Code:Private Sub Form_Load() Dim strSQL As String Dim update1 As String Set cn = New ADODB.Connection cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=" & App.Path & "\warehouses.mdb" cn.Open strSQL = "SELECT * FROM warehouse3" Set rs = New ADODB.Recordset With rs .Open strSQL, cn, adOpenForwardOnly, adLockPessimistic, adCmdText If Not (.EOF And .BOF) Then rs.MoveFirst Call FillFields End If End With End Sub
With red are the update command that for some reason do not update the table!Code:Private Sub cmdAddNew_Click() Dim strSQL As String Dim update1 As String If Option3.Value = True Then If (Text1.Text = "" Or Text2.Text = "") Then MsgBox "Insert Name,Code", vbExclamation, "Invalid Input" Text1.SetFocus Exit Sub End If rs.AddNew rs.Fields("item_name") = Text1.Text rs.Fields("item_id") = Text2.Text rs.Fields("quantity") = IIf(Text3 = "", "0", Text3) rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4) rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5) rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7) rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3") rs.update Call Sum ElseIf Option2.Value = True Then If (Text1.Text = "" Or Text2.Text = "") Then MsgBox "Insert Name,Code", vbExclamation, "Invalid Input" Text1.SetFocus Exit Sub End If update1 = "UPDATE Sum2 SET quantity= quantity - " & Val(Text2.Text) & " WHERE item_id='" & Text3.Text & "'" cn.Execute update1, , adCmdText + adExecuteNoRecords rs.AddNew rs.Fields("item_name") = Text1.Text rs.Fields("item_id") = Text2.Text rs.Fields("quantity") = IIf(Text3 = "", "0", Text3) rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4) rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5) rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7) rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3") rs.update Call Sum ElseIf Option1.Value = True Then If (Text1.Text = "" Or Text2.Text = "") Then MsgBox " Insert Name,Code", vbExclamation, "Invalid Input" Text1.SetFocus Exit Sub End If update1 = "UPDATE Sum1 SET quantity= quantity - " & Val(Text2.Text) & " WHERE item_id='" & Text3.Text & "'" cn.Execute update1, , adCmdText + adExecuteNoRecords rs.AddNew rs.Fields("item_name") = Text1.Text rs.Fields("item_id") = Text2.Text rs.Fields("quantity") = IIf(Text3 = "", "0", Text3) rs.Fields("supplier_name") = IIf(Text4 = "", "Êåíü", Text4) rs.Fields("date_incoming") = IIf(Text5 = "", "Êåíü", Text5) rs.Fields("id_deltioy") = IIf(Text7 = "", "Êåíü", Text7) rs.Fields("store_id") = IIf(Text6.Text = "3", "3", "3") rs.update Call Sum End If End Sub




Reply With Quote
