Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Find.....

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
Please could somebody give me the basic syntax/HELP to be able to search through a DB table... I have the record fields on the form and would like all fields to change to the record that matches the search ID criteria... I have this so far...

strSearch = InputBox("Enter the record ID that you would like to search for...", "Search by Record ID")

FindString = "Select * From pic_table " & _
"WHERE [ID] LIKE '" & strSearch & "%' "
??????????? & [FindString]

...And ideas? Thanks
 
Well that code you've writen seems preety confusing ;)
ok, I'm not sure of exactly what you want to do, but I suppose you know how to connect to a DB via ADO and how to populate a recordset, right? Is your problem on the sintaxe of the FindString is that it?

This should be something like:

FindString = "Select * From pic_table WHERE [ID] = '" & strSearch & "'"

Then just populate a recordset with this string, like

rsRec.Open FindString, your_Connection_HEre, adOpenStatic, adLockReadOnly, adCmdText

Then simply assign each field of the recordset to the correspondent control, like:

Control1=rsRec!Field1
Control2=rsRec!Field2
...

Let me know if you still have problems.
 
Thanks for coming back to me... i have used this code but the error comes back sayng that the object is required...

Private Sub cmdImageFindID_Click()

Dim rs As ADODB.Recordset

strSearch = InputBox("Enter the ID....", "Enter ID")
FindString = ("SELECT * FROM [pic_table] WHERE [id] LIKE '" & strSearch & "*'")

rsRec.Open FindString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\VB Movie Image DB\Databases\images.mdb", adOpenStatic, adLockReadOnly, adCmdText

txtImgID.DataField = rsRec!id
txtImgCadastre.DataField = rsRec!cadastre
txtImgAuthor.DataField = rsRec!author
txtImgDetails.DataField = rsRec!details
txtImgKeywords.DataField = rsRec!keywords
txtImgPosted.DataField = rsRec!posted

End Sub

Any ideas???? Thanks...
 
Is that a copy paste from your code? Because the object required error must be because you use rsRec object, but you've declared it as rs! So rsRec doesn't exist...

So try to replace it by this:

Private Sub cmdImageFindID_Click()

Dim rsRec As New ADODB.Recordset

strSearch = InputBox("Enter the ID....", "Enter ID")

FindString = "SELECT * FROM pic_table WHERE id LIKE '" & strSearch & "'" 'What was the * for btw?

rsRec.Open FindString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=U:\VB Movie Image DB\Databases\images.mdb", adOpenStatic, adLockReadOnly, adCmdText

txtImgID.DataField = rsRec!id
txtImgCadastre.DataField = rsRec!cadastre
txtImgAuthor.DataField = rsRec!author
txtImgDetails.DataField = rsRec!details
txtImgKeywords.DataField = rsRec!keywords
txtImgPosted.DataField = rsRec!posted

End Sub

And why are you using DataField? Wasn't it easier if you did txtBox.Text= resRec!Field? Is there any particular reason you want to use DataField?

Hope this helps
 
Thanks for that.... everything is working fine now.

This forum is the best... ;o)
 
I need to know how VB can regocnize images from a DB. If this is possible (I think it is) please give me any info you have to make this recognition posible. Thanks

ALan (a Programmer from Argentina)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top