Free Lessons
Fast Tips
Topic Index
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
Home > TechHelp > Directory > Access > Search Button < DateAdd | Hide Page Footer >
Back to Search Button    Comments List
search button w cmbo box Upload Images   Link   Email  
Sean Smith       
3 months ago
Hello everyone. Using Access 256, I added the simple search button to a text box and it worked on my form. I'd like to add one to a relational combo box where the user only knows the description displayed, not the primary key which is the secondary key for the input table. Since the description is not in the working table, I've tried changing the Me.Filter code to Me.Filter = "ProductID='" & Me.cmbItemNo.Column(1) & "'" thinking this would link the displayed value to the recorded value. When I run this I get Run time error'3709' and stops at the line modified. Any suggestions on how to do this?
Sami Shamma              
3 months ago
I don't think you need any of this.
Please send the Row Source of the combo box, and we will be able to help.
Sean Smith       
3 months ago
Hi Sami, thank you for helping. Below is the row source of the combo box you requested. It may be obvious, but the full code I'm trying to use comes from the video titled Search Button.

SELECT [tblProducts].[ProductID], [tblProducts].[ItemNo], [tblProducts].[Description] FROM tblProducts ORDER BY [ItemNo];

The working table has ProductID as the secondary key. My users know The ItemNo, which is actually want I want to be able to search, i said description above.
Sami Shamma              
3 months ago
Is the product ID showing in box? If so, reduce its width in format to zero, then your users will only see the item number and description.
Sean Smith       
3 months ago
No. ProductID is the autonumber primary key of the product table and doesn't show in the combo box. ItemNo is what I'd like to search by and is the first visible column in the combo box.
Richard Rost              
3 months ago
You can't filter based on a column of a combo box. You'd have to update the RecordSource of the parent form with a custom SQL statement to show just that record. Something like:

Me.RecordSource = "SELECT * FROM ProductT WHERE ItemNo=""" & MySearchValue & """"
Richard Rost              
3 months ago
MySearchValue could be the column of your combo box if that's what you're using to search...

... & MyCombo.Column(1) & ...

Then put that code in the AfterUpdate event of your combo box.
Sean Smith       
3 months ago
Richard and Sami, thank you for your help on this. I was able to get the search button to work like I wanted it to. Using SQL statements never occurred to me. I tinkered with your suggestion and ended with a final solution that omitted referencing the combo box all together:

Private Sub btnSearchItemNo_Click()
    Dim S As String
    S = InputBox("Enter the description to search:", "Search by Description")
        Me.Filter = "ProductID IN (SELECT ProductID FROM tblProducts WHERE Description Like '*" & S & "*')"
        Me.FilterOn = True
End Sub
Sami Shamma              
3 months ago
Glad all worked out for you.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Search Button.


The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/22/2024 10:10:41 AM. PLT: 1s