Hello there guys!

I need your vb6 expertise. I have a feature of my program with the quantity. What i want is i need a warning message if the quantity is lesser than the minimum quantity for example the minimum of 5 quantity. In my code it will reach to zero quantity before got the warning.

Private Sub txtqty_Change()
On Error GoTo txtqty_change_error:

        Connection
          Set rs = New ADODB.Recordset
            SQL = "SELECT qty FROM tblstocks WHERE Category_Description LIKE '%" & Replace(Trim(lblx), "'", "''") & "%' ORDER BY Category_Description"
            ' Percentage (%) sign is used as a wildcard character in the "LIKE" clause.
                rs.Open SQL, cn, 3, 3
                    If Val(txtqty.Text) > rs!Qty Then
                        MsgBox "Insuffecient Quantity of Stock", vbExclamation, ""
                        txtqty.SetFocus
                    ElseIf txtqty.Text = "" Then
                    txtcost.Text = Val(txtcost.Text) - Val(Text11.Text)
                    Else
                            Text11 = Val(txtqty.Text) * Val(txtamount.Text)
                            Text2.Text = Val(txtqty.Text) * Val(txtamount.Text)
                        If txtqty.Text > Text4.Text Then
                            Text9.Text = Val(Text8.Text) - Val(txtqty.Text)
                        ElseIf txtqty.Text < Text4.Text Then
                            Text9.Text = Val(Text8.Text) - Val(txtqty.Text)
                        ElseIf txtqty.Text = Text4.Text Then
                            Text9.Text = Val(Text8.Text) - Val(Text4.Text)
                        End If
                    End If
    Exit Sub
    txtqty_change_error:
    MsgBox err.Description & " _ " & err.Number & ".", vbCritical

    End Sub

It is better to give a proper name to text boxes and post a neat code (your if conditions are not clear). because reader cant understand what you have done.
Are you sure QTY value pass to the VB form? if yes, close record set at last. (Write rs.close() in line 28)

its almost all green..its not readable,by the way its better to use keydown than change i guess.and pls make your textbox name specific thanks.

Hi,

All the validation code has to be written in "_Validate" event, not change event...

Regards
Veena

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.