how can i determine that may text1.text is equal to my product code?? heres 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 rs.Fields!pcode = Text1.Text Then
MsgBox "The Product Code is Already Exist!", vbCritical
Exit Sub
Else
Dim s
s = "INSERT INTO Product (pcode, brandname, genericname, price, pstock) VALUES ('" + Text1.Text + "','" + Text2.Text + "','" + Text3.Text + "','" + Text4.Text + "','" + Text5.Text + "')"
cn.Execute s, adExecuteNoRecords
MsgBox "Product Successfully Added", vbInformation
Call Form_Load
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If

Ezzaral commented: 49 posts and you still refuse to use code tags? -3

Recommended Answers

All 2 Replies

rs.Open "Select PCODE from Product WHERE PCODE = '" & Trim(Text1.Text) & "'", cn, adOpenKeyset, adLockPessimistic
If rs.BOF = False Then
    MsgBox "The Product Code is Already Exist!", vbCritical
    If rs.State Then rs.Close
    Set rs = Nothing
    Exit Sub
Else

thanks your my hero :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.