[RESOLVED] Execute command will not update the database
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:
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
And the button click:
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
With red are the update command that for some reason do not update the table!
Re: Execute command will not update the database
I have spent 3 hours trying to find out why the code isnt working and the problem was that the text boxes were upside down in the form...
Re: Execute command will not update the database
Quote:
Originally Posted by
vagos7
I have spent 3 hours trying to find out why the code isnt working and the problem was that the text boxes were upside down in the form...
Upside down? :confused:
Re: [RESOLVED] Execute command will not update the database
Text3 was where text2 was supposed to be in the form.It thought it was text3 up and text2 down while it was the other way round. And the problem was that i was importing the wrong values because text2 was handling the item_id.