Last year someone posted a question asking for help creating a search function for a library database here: https://www.pcreview.co.uk/forums/thread-1182888.php. The idea was to enter some words in the book title, be presented with a list of hits, and be able to find the book category by clicking on one of the books.
Then, someone else posted an answer as I have typed in below (I cannot find the previous post).
Assume the table named TblBook has the following categories:
BookID
BookTitle
Category
Create a query named QryBookSearch based on TblBook including all three fields in the order shown above.
Set Sort for BookTitle in QryBookSearch to ascending.
Put the following expression in the Criteria of BookTitle in QryBookSearch:
Like "*" & Forms!FrmSearch!SearchForTitle & "*"
Make a form named FrmSearch and:
1. Add a textbox named SearchForTitle
2. Put the following code in the AfterUpdate event of SearchForTitle:
Me!MyBookList.Requery
3. Add a textbox named BookCategory
4. Add a listbox named MyBookList, and do the following:
a. Set Row Source to QryBookSearch
b. Set Bound Column to 1
c. Set Column Count to 3
d. Set Column Width to 0;1.5;0
e. Put the following code in the AfterUpdate event:
Me!BookCategory = Me!MyBookList.Column(2)
Enter the title of the book to be searched for in SearchForTitle and press enter. The titles of all books that contain the words entered in the textbox appear in the listbox. If one of the books is selected, its category appears in the BookCategory textbox.
I am using Access 97. I have followed the instructions above several times (each in a new copy of the original database). By doing it several times, I hope I have eliminated the possibility of bad syntax. I have also carefully checked everything each time.
If I open the QryBookSearch query, it presents me with a window into which I can type a string and it gives me a list of matching books. However, when I open the FrmSearch form and enter a string into the SearchForTitle textbox, it gives me the following message:
Microsoft Access can't find the macro 'Me!MyBookList.'
The macro (or its macro group) doesn't exist, or the macro is new and hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macro's macro group was last saved under.
Any help would be greatly appreciated.
Mike
Then, someone else posted an answer as I have typed in below (I cannot find the previous post).
Assume the table named TblBook has the following categories:
BookID
BookTitle
Category
Create a query named QryBookSearch based on TblBook including all three fields in the order shown above.
Set Sort for BookTitle in QryBookSearch to ascending.
Put the following expression in the Criteria of BookTitle in QryBookSearch:
Like "*" & Forms!FrmSearch!SearchForTitle & "*"
Make a form named FrmSearch and:
1. Add a textbox named SearchForTitle
2. Put the following code in the AfterUpdate event of SearchForTitle:
Me!MyBookList.Requery
3. Add a textbox named BookCategory
4. Add a listbox named MyBookList, and do the following:
a. Set Row Source to QryBookSearch
b. Set Bound Column to 1
c. Set Column Count to 3
d. Set Column Width to 0;1.5;0
e. Put the following code in the AfterUpdate event:
Me!BookCategory = Me!MyBookList.Column(2)
Enter the title of the book to be searched for in SearchForTitle and press enter. The titles of all books that contain the words entered in the textbox appear in the listbox. If one of the books is selected, its category appears in the BookCategory textbox.
I am using Access 97. I have followed the instructions above several times (each in a new copy of the original database). By doing it several times, I hope I have eliminated the possibility of bad syntax. I have also carefully checked everything each time.
If I open the QryBookSearch query, it presents me with a window into which I can type a string and it gives me a list of matching books. However, when I open the FrmSearch form and enter a string into the SearchForTitle textbox, it gives me the following message:
Microsoft Access can't find the macro 'Me!MyBookList.'
The macro (or its macro group) doesn't exist, or the macro is new and hasn't been saved.
Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macro's macro group was last saved under.
Any help would be greatly appreciated.
Mike
Last edited: