1 Replies - 953 Views - Last Post: 26 September 2017 - 08:30 AM Rate Topic: -----

#1 shiv13  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 19-September 17

search button not working properly

Posted 26 September 2017 - 05:46 AM

I am trying to search record from table cosmetic in ms access what happening is there is errors for database connection error is operation can not perform while object is open the same error comes for recordset object also when i coment those line my code is running but then after putting any is code is only fetching first record in table even if that particular id is not present in table

Private Sub cmdcheck_Click()
search = cmbitem.Text
c.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\project\Database\dataBase.mdb;Persist Security Info=False"
s = "select * from Cosmetics where Cosmetic Name=" & search & ""
r.Open s, c, adOpenDynamic, adLockOptimistic
txtcosid.Text = r.Fields(0)
txtqt.Text = r.Fields(2)
txtprice.Text = r.Fields(3)
c.Close
If r.EOF Then
MsgBox "Record not found", vbCritical, "cosmetic Shop Management"
End If
End Sub


i have highlight those two lines where error occur please help

This post has been edited by modi123_1: 26 September 2017 - 06:47 AM
Reason for edit:: removing color tags


Is This A Good Question/Topic? 0
  • +

Replies To: search button not working properly

#2 andrewsw  Icon User is offline

  • the case is sol-ved
  • member icon

Reputation: 6374
  • View blog
  • Posts: 25,755
  • Joined: 12-December 12

Re: search button not working properly

Posted 26 September 2017 - 08:30 AM

If you have errors you should quote them exactly. (It also doesn't help that your opening text is one unbroken block. Please form proper sentences.)

Because your field name has a space you need to surround it with square brackets. Or, preferably, don't use spaces or other unusual characters in field names.

If you are providing a text criteria then it needs to be surrounded with single quotes. Or, preferably, use parameterized queries.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1