I am preparing a Business Management System, in which the user enters the details of purchase and sale, where item number identifies the stock availability. Suppose i purchased item1 as Business Stock, it was not in the stock, it is updated in table 4. But if it exists, i gave an SQL query, with Update Command.
Quantity= qty is updating, but Quantity = Quantity + qty is not working.

con.Execute ("update table4 set Quantity = Quantity + qty where Item_code='" & Text3.Text & "'")

While executing this command, the sustem shows the error specified in the title. The code is given Below, if anyone thinks that it can be solved, kindly revert me at [email snipped]


Dim con As New ADODB.Connection
Dim res As New ADODB.Recordset
Dim res1 As New ADODB.Recordset
Dim sql As String
Dim sql2 As String
Dim sql1 As String
Dim qty As String
Dim sql3 As String



Private Sub Command1_Click()
Text7.Text = Val(Text5.Text) * Val(Text6.Text)
sql = ""
sql = sql + "insert into table2 values('" & Text2.Text & "','" & Text1.Text & "','" & Text3.Text & "','" & Text4.Text & "','" & Text5.Text & "','" & Text6.Text & "','" & Text7.Text & "')"
res.Open "select * from table2 where reciept='" & Text2.Text & "'", con, adOpenDynamic, adLockOptimistic
If res.EOF = False Then
MsgBox "Bill no. already Exists", vbCritical, "Verification"

Text2.Text = ""
res.Close

Else
con.Execute sql
MsgBox "Bill Submitted"
res.Close
End If
sql1 = ""
sql1 = sql1 + "insert into table4 values('" & Text3.Text & "','" & Text5.Text & "')"
res1.Open "select * from table4 where item_code='" & Text3.Text & "'", con, adOpenDynamic, adLockOptimistic

If res1.EOF = False Then
   
    
MsgBox "Item Already Exists in Stock", vbCritical, "Verification"
res1.Close
qty = Text5.Text

con.Execute ("update table4 set Quantity = Quantity + qty where Item_code='" & Text3.Text & "'")


Else
con.Execute sql1

res1.Close
End If
End Sub

Private Sub Command2_Click()
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
End Sub

Private Sub Form_Load()
Text1.Text = Date
End Sub

Private Sub Form_Activate()
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database21.mdb;Persist Security Info=False"
con.Open
End Sub

Attachments also there, please help if you can, i want the project complete by tomorrow. :sweat:

Line 39 should probably look something like this:

con.Execute ("update table4 set Quantity = Quantity + " & qty & " where Item_code='" & Text3.Text & "'")

Or, for consistency's sake, get rid of line 37 and change line 39 to:

con.Execute ("update table4 set Quantity = Quantity + " & Text5.Text & " where Item_code='" & Text3.Text & "'")

Hope this helps.

commented: the post is replied with the perfect query updated, which was not solved by 6 students, 3 lecturers and 7 engineers working in a company. +0

Line 39 should probably look something like this:

con.Execute ("update table4 set Quantity = Quantity + " & qty & " where Item_code='" & Text3.Text & "'")

Or, for consistency's sake, get rid of line 37 and change line 39 to:

con.Execute ("update table4 set Quantity = Quantity + " & Text5.Text & " where Item_code='" & Text3.Text & "'")

Hope this helps.

Man, Thank you so much, i was stuck in this situation past one week. This being my very first software for minor project, i was stuck. And the thing is, 3 assistant professors, 7 engineers working in a different companies and 6 students from my batch, weren't able to find the solution. Thanks so much. Stay in touch man. :cool:

Glad to help. Be sure to mark the thread "Solved".

Also, one thing about coding errors...sometimes it has nothing to do with how smart or experienced you are...sometimes you just get in one of those situations where you beat your head against a problem for hours, then someone peeks over your shoulder, looks at it for 10 seconds, and says, "Oh, the problem is right THERE." No reflection on the abilities of the coder, it has happened to all of us at one time or another. Keeps us all humble.

We just have to make sure it doesn't happen OFTEN... :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.