Link to home
Start Free TrialLog in
Avatar of stacydr
stacydrFlag for United States of America

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of rockiroads
rockiroads
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
got duplicate end sub in the code, so ensure you ignore one of them
Avatar of stacydr

ASKER

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.
Avatar of stacydr

ASKER

Got it -- nevermind ...

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

thanks again!!
def a pleasure
Avatar of stacydr

ASKER

def awesome working with you -- your codes are the best! thanks