CGehlhausen
Programmer
I have a series of search fields across the top of a form, with detail rows below them - allowing the user to search a large database by several fields at once.
Unfortunately when they type * for a wildcard, the sendkeys F2 (escape) is read as a SHIFT +F2 which brings up the zoom window.
Does anyone know how to disable the zoom window?
Or is there an alternate way of coding a field escape?
Unbelievably this database is Access '97. :{
Sample code (for 1 of 4 search boxes):
Private Sub SearchItem_Change()
On Error GoTo Err_SearchItem_Change
Dim frm As Form
Dim OrgLength, PosnStart, PosnEnd, PosnTotl As Integer
Dim text, strFilter, OrgFilter, OrgFltrBU, OrgLft, OrgRgt As String
' Save the Original Search Filter
OrgFilter = [Forms]![DR_Items].[Filter]
' Set the Current Form
Set frm = [Forms]![DR_Items]
' Go to the Property & Sort Ascending
Forms![DR_Items]![ITEM].SetFocus
DoCmd.RunCommand acCmdSortAscending
' Get Search String
text = Me![SearchItem].Value
'Check for blank entry field
If text = "" Then
frm.Filter = OrgFilter
GoTo Exit_SearchItem_Change
End If
' Set the Search Property
strFilter = "([ITEM] Like " & "'" & text & "*')"
' Apply the Filter
If OrgFilter = "([ITEM] Like '*')" Then
frm.Filter = strFilter
Else
If InStr(OrgFilter, "[ITEM]") > 0 Then
OrgFltrBU = OrgFilter
OrgLength = Len(OrgFltrBU)
PosnStart = InStr(OrgFltrBU, "[ITEM]")
PosnEnd = InStr(PosnStart, OrgFltrBU, ")")
PosnTotl = PosnEnd - PosnStart
If text = "" Then
Mid(OrgFltrBU, PosnStart, PosnTotl) = "[ITEM] Like '*' "
Else
OrgLft = Left(OrgFltrBU, (OrgLength - (PosnTotl + (OrgLength - PosnEnd) + 1)))
OrgRgt = Right(OrgFltrBU, (OrgLength - PosnEnd))
OrgFltrBU = OrgLft & "[ITEM] Like '" & text & "*')" & OrgRgt
End If
frm.Filter = OrgFltrBU
Else
frm.Filter = strFilter & " AND " & OrgFilter
End If
End If
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True
' Exit Options
If CurrentRecord > 0 Then
GoTo Exit_SearchItem_Change
Else
GoTo NoRecords_SearchItem_Change
End If
'End If
NoRecords_SearchItem_Change:
MsgBox "No Records match your filter."
' Remove the Filter
frm.Filter = OrgFilter
Me!SearchItem = ""
GoTo Exit_SearchItem_Change
Exit_SearchItem_Change:
' Set the Focus Back to the Search Field
OrgFilter = ""
Me!SearchItem.SetFocus
SendKeys "{F2}", True
Exit Sub
Err_SearchItem_Change:
MsgBox Err.Description
Resume Exit_SearchItem_Change
End Sub
All's well that Ends!
Unfortunately when they type * for a wildcard, the sendkeys F2 (escape) is read as a SHIFT +F2 which brings up the zoom window.
Does anyone know how to disable the zoom window?
Or is there an alternate way of coding a field escape?
Unbelievably this database is Access '97. :{
Sample code (for 1 of 4 search boxes):
Private Sub SearchItem_Change()
On Error GoTo Err_SearchItem_Change
Dim frm As Form
Dim OrgLength, PosnStart, PosnEnd, PosnTotl As Integer
Dim text, strFilter, OrgFilter, OrgFltrBU, OrgLft, OrgRgt As String
' Save the Original Search Filter
OrgFilter = [Forms]![DR_Items].[Filter]
' Set the Current Form
Set frm = [Forms]![DR_Items]
' Go to the Property & Sort Ascending
Forms![DR_Items]![ITEM].SetFocus
DoCmd.RunCommand acCmdSortAscending
' Get Search String
text = Me![SearchItem].Value
'Check for blank entry field
If text = "" Then
frm.Filter = OrgFilter
GoTo Exit_SearchItem_Change
End If
' Set the Search Property
strFilter = "([ITEM] Like " & "'" & text & "*')"
' Apply the Filter
If OrgFilter = "([ITEM] Like '*')" Then
frm.Filter = strFilter
Else
If InStr(OrgFilter, "[ITEM]") > 0 Then
OrgFltrBU = OrgFilter
OrgLength = Len(OrgFltrBU)
PosnStart = InStr(OrgFltrBU, "[ITEM]")
PosnEnd = InStr(PosnStart, OrgFltrBU, ")")
PosnTotl = PosnEnd - PosnStart
If text = "" Then
Mid(OrgFltrBU, PosnStart, PosnTotl) = "[ITEM] Like '*' "
Else
OrgLft = Left(OrgFltrBU, (OrgLength - (PosnTotl + (OrgLength - PosnEnd) + 1)))
OrgRgt = Right(OrgFltrBU, (OrgLength - PosnEnd))
OrgFltrBU = OrgLft & "[ITEM] Like '" & text & "*')" & OrgRgt
End If
frm.Filter = OrgFltrBU
Else
frm.Filter = strFilter & " AND " & OrgFilter
End If
End If
' Set FilterOn property; form now shows filtered records.
frm.FilterOn = True
' Exit Options
If CurrentRecord > 0 Then
GoTo Exit_SearchItem_Change
Else
GoTo NoRecords_SearchItem_Change
End If
'End If
NoRecords_SearchItem_Change:
MsgBox "No Records match your filter."
' Remove the Filter
frm.Filter = OrgFilter
Me!SearchItem = ""
GoTo Exit_SearchItem_Change
Exit_SearchItem_Change:
' Set the Focus Back to the Search Field
OrgFilter = ""
Me!SearchItem.SetFocus
SendKeys "{F2}", True
Exit Sub
Err_SearchItem_Change:
MsgBox Err.Description
Resume Exit_SearchItem_Change
End Sub
All's well that Ends!