stacydr
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
got duplicate end sub in the code, so ensure you ignore one of them
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.
I tried but no luck..
Thanks, S.
ASKER
Got it -- nevermind ...
Me.List16.RowSource = strSQL & "ORDER By Company.Company_Name"
thanks again!!
def a pleasure
Me.List16.RowSource = strSQL & "ORDER By Company.Company_Name"
thanks again!!
def a pleasure
ASKER
def awesome working with you -- your codes are the best! thanks