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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code for find command in books dataset

Status
Not open for further replies.

mrholtsr

Programmer
Dec 3, 2001
18
US
I have created a database to catalogue my library. I have been able to get most of the code to work. Could someone share with me the basic code for the find command. Thanks, Ray Holt
 
Find in what exactly?

You can issue an SQL statement to retrieve a specific item.

You can issue a "Find" (or "FindFirst", FindNext", "FindLast") in a recordset.

You can filter a recordset for specified values.

How are you interacting with the database? Can you provide a better definition of the context in which you want to "find" something?

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
It is just a simple database file of the books in my home library and I would like to be able to go to a specific book in the list. I know it should be easy, but I can't seem to get it to work. The other commands such as add work perfectly. Thanks, Ray Holt
 
Still haven't answered the question exactly but here are a few assumptions. Confirm their truth (or lack thereof.)

[li]You have this information stored in a MS/JET (i.e. Access) database[/li]
[li]You are using DAO (Data Access Objects) to talk to the database.[/li]
[li]You are displaying the list of books in a Datagrid on a VB form and that DataGrid has a Data Control as it's recordsource.[/li]

Now ... if all that is true, and assuming that the Data Control is called "Data1", then one way to find a particular book is
Code:
With Data1.Recordset
   .FindFirst "BookName = 'Moby Dick'"
   If .NoMatch then MsgBox "Book does not exist."
End With

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
If all that is NOT true, then golom's code might not work. Hence his request for more specific information.

Bob
 
Hi, I have made progress, but I still cannot use the find button. What I want is have a search item so that I can search titles by name. It is a Foxpro 2.5 database and I have brought it inot VB5. I have hundreds of books in my personal library and I just want to organize them so I can find them. I hope I have made myself clear. What I want is a general find function in which I can enter the title of a book and go to it in the dataset which is name ProfHolt. Thanks, Ray Holt
 
I'm afraid you haven't made yourself clear, no. Of Golom's 3 assumptions, you have only clarified the first. Would you mind explaining HOW you're doing what you're doing, rather than WHAT you're doing? I believe we're clear on that part.

Bob
 
I used the application wizard to bring the books database in from fpw2.6. The wizard put menu items on the form but not a search function. I placed a command object on the form and tried to code it to do a search based on criteria I establish to locate a particular book and it's location in my library. I want the search to bring up a user input box in which I can tell what I want it to search for. I still don't know if I have made myself clear. Thanks, Ray
 
Sorry, I'm unfamiliar with the Application Wizard.

Bob
 
I am using a foxpro2.6 database. I am using DAO to talk to the database, and I am viewing the database in a VBGrid. I would like to be able to use a search to locate titles in a list that contains several thousand books. The code Golom gave me finds a specific book by coding that books name. How do I get the search just give me a text box in which I can then type the title of the book I want to find. Thanks, and I apologize if I am not making myself clear. Ray Holt
 
Something like this?
Code:
With Data1.Recordset
   .FindFirst "BookName = '" & txtSearch.Text & "'"
   If .NoMatch then MsgBox txtSearch.Text & " does not exist."
End With

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top