Using VBA to filter a field by first letter?

I'm working on a small inventory database that lists all of the software at my company.  I am attempting to make a form that allows a user to search for a software package by first letter of the application name.

I've tried to write some VBA code to do this, but I am new to A2k and VBA so I am sure I am missing something since I cannot get this to work.  I always get an error stating that I cannot assign a value to the Me.Filter action.  The following is the code I was trying to use:

Begin Code
----------------------------------
Private Sub Sort_By_First_Letter_Of_Program_Name_Click()
On Error GoTo Err_Sort_By_First_Letter_Of_Program_Name_Click
    MsgBox "Hello World"
    Dim strLetter As String, strInput As String
    strInput = "Please type in the first letter of the program name: "
    strLetter = InputBox(Prompt:=strInput)
    Me.Filter = "ProgramName = LIKE M*"
    Me.FilterOn = True


   

Exit_Sort_By_First_Letter_Of_Program_Name_Click:
    Exit Sub

Err_Sort_By_First_Letter_Of_Program_Name_Click:
    MsgBox Err.Description
    Resume Exit_Sort_By_First_Letter_Of_Program_Name_Click
   
End Sub
----------------------------------------
End Code

I am beginning to think I may need to use ADO or DAO to do this, but I am unfamiliar with how to use either one of them.  Any pointers or hints would be greatly appreciated.
cjwetiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nexusnationCommented:
try the below.

Begin Code
----------------------------------
Private Sub Sort_By_First_Letter_Of_Program_Name_Click()
On Error GoTo Err_Sort_By_First_Letter_Of_Program_Name_Click
   MsgBox "Hello World"
   Dim strLetter As String, strInput As String
   strInput = "Please type in the first letter of the program name: "
   strLetter = InputBox(Prompt:=strInput)
   Me.Filter = "[ProgramName] = "LIKE" & strinput & "*"
   Me.FilterOn = True

Exit_Sort_By_First_Letter_Of_Program_Name_Click:
   Exit Sub

Err_Sort_By_First_Letter_Of_Program_Name_Click:
   MsgBox Err.Description
   Resume Exit_Sort_By_First_Letter_Of_Program_Name_Click
   
End Sub
----------------------------------------
End Code
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Arthur_WoodCommented:
very very minor item--this line:

Me.Filter = "[ProgramName] = "LIKE" & strinput & "*"

will generate an error.


Change it to:

Me.Filter = "[ProgramName] LIKE '" & strinput & "*'"

1) notice the space after the work LIKE, and

2) the strInput needs to be enclosed in '....' s

AW
0
cjwetiAuthor Commented:
I tried the code you posted nexusnation, and now I am getting a Type Mismatch error.  

At first I thought it might just be a missing quotation mark or the use of strInput in the Me.Filter line instead of strLetter, but I get the same error regardless of which variable I use.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cjwetiAuthor Commented:
I tried the code you posted nexusnation, and now I am getting a Type Mismatch error.  

At first I thought it might just be a missing quotation mark or the use of strInput in the Me.Filter line instead of strLetter, but I get the same error regardless of which variable I use.
0
cjwetiAuthor Commented:
Arthur Wood,

Your line does work, however I had to use strLetter instead of strInput as the variable.

Thanks for the fast response nexusnation and Arthur.  I'll award points here shortly.
0
cjwetiAuthor Commented:
Fast answer, minor issues with line format and incorrect variable use but other than that right on.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.