Solved

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

Posted on 2009-04-11
5
741 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
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now