all i want is if the value of my product stock is 0 then the message box show for example theres no more product stock and also i want is if the user inputted higher value in my text2.text for example my product stock left is 5 if he/she inputted 6 the message box show theres no more product stock

this is my code

Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\Inventory System\PharmacyInventory.mdb;Jet OLEDB:System Database=system.mdw;", "admin", ""
Set rs = New ADODB.Recordset
rs.Open "Select * from Product", cn, adOpenKeyset, adLockPessimistic
If Text2.Text = "" Then
MsgBox "Please Input the Quantity Fields", vbCritical, "Product Return"
End If
If Val(rs!pstock) < 0 Then
MsgBox "There's no More to Return", vbCritical
Exit Sub
ElseIf IsNull(rs!pstock) = True Then
MsgBox "There's no More to Return", vbCritical
rs.Fields![pstock] = Val(rs.Fields![pstock]) - Val(Text2.Text)
cn.Execute "INSERT INTO ProductReturn (drno, pcode, scode, quantity, unit, pdescription, [date]) VALUES ('" + Combo1.Text + "','" + Label8.Caption + "','" + Label9.Caption + "','" + Text2.Text + "','" + Label11.Caption + "','" + Text4.Text + "',#" + Label10.Caption + "#)"
Combo1.Text = ""
Label8.Caption = ""
Text2.Text = ""
Label11.Caption = ""
Text4.Text = ""
Label9.Caption = ""
Label10.Caption = ""
MsgBox "Return Successful", vbInformation
Call grd_Data_Loader
End If

Something like that your code does seems to do. And what is the question?

it looks correct for checking if the value is less then 0 or if it is null.
if you want to check the value from the text box then you can add another if statement. also you may want to change if the statement from < 0 to <= 0. to check if the value is 0 or less with the text and the current stock you could do something like

dim checkstock as integer
checkstock = (cint(textbox2.text) - val(rs!pstock) )
if checkstock <= 0 Then
'your message here
end if

sorry that should be

checkstock = ( val(rs!pstock) - cint(textbox2.text))
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.