Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-11
5
Medium Priority
?
761 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 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

885 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