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
Text2.SetFocus
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
Else
rs.Fields![pstock] = Val(rs.Fields![pstock]) - Val(Text2.Text)
rs.Update
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

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
This article has been dead for over six months. Start a new discussion instead.