Results 1 to 2 of 2
2004-04-19, 00:23 #1
- Join Date
- Feb 2003
- Northfield, Minnesota, USA
- Thanked 0 Times in 0 Posts
Search by part of last name (Access 2000)
I have set up a button with VB code to open a form based on the last name entered. I want to change it so that I can look up the Jacobson and Jacobsen last names by typing Jacob.
My trouble is that every time I try to use a wildcard in my VB it seems to be looking literally for a
2004-04-19, 00:57 #2
- Join Date
- Nov 2001
- Arlington, Virginia, USA
- Thanked 3 Times in 3 Posts
Re: Search by part of last name (Access 2000)
I don't see where you are using a wildcard in code posted, which looks like "wizard" generated code. Here is simple example, using Northwind "Products" form:
Public Sub OpenFormWithWildcard()
Dim strFrm As String
Dim strLike As String
Dim strCriteria As String
' Northwind Products form:
strFrm = "Products"
strLike = "Ch"
strCriteria = "<!t>[ProductName]<!/t> Like '" & strLike & "*'"
DoCmd.OpenForm strFrm, , , strCriteria
When this sub runs, the NW "Products" form is opened, filtered to display only those products whose ProductName begins with "Ch" (6 records in my copy of Northwind). Note use of Like operator and asterisk for wildcard:
<pre>strCriteria = "<!t>[ProductName]<!/t> Like '" & strLike & "*'"</pre>
You should be able to adapt this for your own project. For more info on using Like operator, recommend look up "Like Operator" topic in Access Help.