?
Solved

MS Access Text Box/Command Button to be used as Search for List Box Population

Posted on 2009-04-11
5
Medium Priority
?
757 Views
Last Modified: 2013-11-28
Hi-  (Sorry for not using proper naming conventions)
I have a ListBox (List16)
I have a Text Box (Text67)
I have a Command Button (Command71)

The data being looked at is in Table: Company, Field: Company_Name.
My Company Unique ID is called: DUNS_Number
My main form is called: CompanyMain

I would like the user to be able to add something like this to Text67
Ash*

And then they could click Command71 and List16 would show a list of companies that contained Ash.. such as Ashland Chemicals or Ashley Corporation ect.

I woudn't mind if they could use the * at the beginning either..
*Ash*
Returns: Ashland Chemical or Stashouse Brick

I also have two other ListBoxes (List45 and List53) which would have to be set to null at the end of the process.

I was reading another thread about this but I got myself confused..
I don't even know if this is what I should be using (as I mentioned I got this from another thread) so a complete re-write is fine with me too..

Code is below -
Thanks for any help.
Stacy



Dim strSQL As String
 
'Set row source for list box
   strSQL = "SELECT Company.DUNS_Number, Company_Company_Name, "
   strSQL = strSQL & "WHERE Company_Company_Name like '" & [Forms]![CompanyMain]![Text69] & "*'"
 
'Update List Box with search results
   Me!List16.RowSource = strSQL
       DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70
    Me.List45 = Null
    Me.List53 = Null
 
 
End Sub

Open in new window

0
Comment
Question by:stacydr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 24122964
Im getting used to your db but getting more confused by the access generated names, lol

Dont bother with the user entering *, just add it in yourself

on the click event of Command71, add your code

private sub Command71_Click()

Dim strSQL As String
 
'Set row source for list box
   strSQL = "SELECT Company.DUNS_Number, Company_Company_Name "
   strSQL = strSQL & "WHERE Company_Company_Name like '*" & NZ(Me.Text67,"") & "*'"
 
'Update List Box with search results
    Me.List16.RowSource = strSQL

    Me.List45 = Null
    Me.List53 = Null
end sub
 
 
End Sub
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 24122969
got duplicate end sub in the code, so ensure you ignore one of them
0
 
LVL 2

Author Comment

by:stacydr
ID: 24124489
Again - works great -- but :) anyway we can add an Order By Company_Name somewhere in here for the results...
I tried but no luck..
Thanks, S.
0
 
LVL 2

Author Comment

by:stacydr
ID: 24124496
Got it -- nevermind ...

Me.List16.RowSource = strSQL & "ORDER By Company.Company_Name"

thanks again!!
def a pleasure
0
 
LVL 2

Author Closing Comment

by:stacydr
ID: 31569199
def awesome working with you -- your codes are the best! thanks
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question