G
Guest
On my form, I have 2 unbound txt boxes, one named Search_Name and One named
Search_Town.
There is a command button named CmdSearch.
On clicking the CmdSearch, the following code runs. In previous versions of
access, it returns all records with names and/or towns that are entered in
the text boxes and filters out records that do not match the search criteria.
Why does this code not nork in Access 2007?
Private Sub CmdSearch_Click()
'myfilter is the variable to be built that will be the filter string
Dim myfilter As String
'like is in there to allow near matches, not exact matches
'the forms is telling that it is a form and is the form FrmUpdtAdult
' & NAME
' the asterisk is a wildcard for the near match
' the object is put into the string inside single quotes
'If name is blank we use an * to select all names within the
' balance of the filter criteria
myfilter = "[NAME]like "
If IsNull([Search_name]) Then
myfilter = myfilter + "'*'"
Else
myfilter = myfilter + "'" + Forms![FrmUpdtAdult]![Search_name] + "*'"
End If
' This section searches for a town near-by with a textboxt named "Search_town"
' If Search_town is not blank then the town is appended to the filter string.
If IsNull(Search_Town) = False Then
myfilter = myfilter + " and " + "[TOWN] LIKE " + "'" +
Forms![FrmUpdtAdult]![Search_Town] + "*'"
End If
' Finally, the DoCmd.Applyfilter will cause the filter string 'myfilter' to
' be applied to the query for the form. Since we are using the current query
' that the form itself is using we do not specifically identify the query
after the
' Applyfilter command but use a comma to default the current query and then
' at the end of the command we pass the filter string we have built!
DoCmd.ApplyFilter , myfilter
' The setFocus will put the cursor in the spot identified by Me![nnnnn]
Me![Name].SetFocus
End Sub
Search_Town.
There is a command button named CmdSearch.
On clicking the CmdSearch, the following code runs. In previous versions of
access, it returns all records with names and/or towns that are entered in
the text boxes and filters out records that do not match the search criteria.
Why does this code not nork in Access 2007?
Private Sub CmdSearch_Click()
'myfilter is the variable to be built that will be the filter string
Dim myfilter As String
'like is in there to allow near matches, not exact matches
'the forms is telling that it is a form and is the form FrmUpdtAdult
' & NAME
' the asterisk is a wildcard for the near match
' the object is put into the string inside single quotes
'If name is blank we use an * to select all names within the
' balance of the filter criteria
myfilter = "[NAME]like "
If IsNull([Search_name]) Then
myfilter = myfilter + "'*'"
Else
myfilter = myfilter + "'" + Forms![FrmUpdtAdult]![Search_name] + "*'"
End If
' This section searches for a town near-by with a textboxt named "Search_town"
' If Search_town is not blank then the town is appended to the filter string.
If IsNull(Search_Town) = False Then
myfilter = myfilter + " and " + "[TOWN] LIKE " + "'" +
Forms![FrmUpdtAdult]![Search_Town] + "*'"
End If
' Finally, the DoCmd.Applyfilter will cause the filter string 'myfilter' to
' be applied to the query for the form. Since we are using the current query
' that the form itself is using we do not specifically identify the query
after the
' Applyfilter command but use a comma to default the current query and then
' at the end of the command we pass the filter string we have built!
DoCmd.ApplyFilter , myfilter
' The setFocus will put the cursor in the spot identified by Me![nnnnn]
Me![Name].SetFocus
End Sub