Private Sub btn_addc_Click() On Error Resume Next If Me.txtAddc.Text = "" Then MsgBox "Please fill up", vbInformation, "ADD CATEGORY" Exit Sub End If If Me.btn_addc.Caption = "ADD" Then If rs.State = adStateOpen Then rs.Close rs.Open " Select * From tbl_category WHERE CategoryList ", db, adOpenStatic, adLockOptimistic If rs.RecordCount > 0 Then MsgBox "The Category you have entered is already Existed", vbCritical, "Error" btn_refresh_Click Me.txtAddc.Text = "" Me.txtAddc.SetFocus Else With rs .AddNew .Fields("CategoryList") = Me.cmb_addc.Text .Update End With MsgBox " Category Successfully Added.", vbInformation, "CATEGORY" btn_refresh_Click End If End If End Sub
Jump to Post
Why do you assume that if RecordCount is greater than zero the record already exists?
Do you not allow to update existing records?
Your indentation is bad, Very bad. Very bad. (Paraphrasing an Amrican...)
Assuming you are using Visual Studio, set breakpoints and dive into a wonderful debugger to watch …
Jump to Post
This type of post is getting to be standard on this site. If there is a point to it, we're left to guess what that point is. It's annoying. I see it tagged with "Visual Basic 6", which I know next to nothing about EXCEPT that Microsoft told everyone not …
All 7 Replies
Be a part of the DaniWeb community
We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.