Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disable Zoom? Or Escape current field without F2?

Status
Not open for further replies.

CGehlhausen

Programmer
Dec 17, 2004
14
US
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!
 
What are you trying to accomplish with the F2 keystroke? It seems you are trying to reset the field to what it was before, except that this is in the successful side of the filter application, so there are records that would match your filter. Why would you want to reset the field then?

Can you explain the behavior that you want to see by using this command?
 
This script runs OnChange, so that as the user types, the filter is run - saving them from hitting "Enter".

To do this I need to get back into the field and place the cursor at the end so they can keep typing.

I tried ESC, Right Arrow, everything I could think of, then happened upon F2. Works great until they type something requiring a SHIFT, such as *.


All's well that Ends!
 
what about...

With Me!SearchItem
.SetFocus
.SelStart = len(.text)
End With


But... what if the person realizes that they have entered a piece of information wrong?

What if they enter "infroamtion" and realize they have made several spelling errors. They click in the middle of the word and delete the 'r'. Their next move is to insert the 'r' after the 'o', but now your code has left them with the cursor at the end of the string.

For users I have worked with, this potential headache is more than enough reason to move the Filter construction to an AfterUpdate event, and make the user hit Tab or Enter.

Alternately, you can use the SelStart property to return the location of the cursor before the change is applied to the textbox. Capture the SelStart value, do your Filtering, and then set the SelStart from my above code to the original captured value.

Hope this helps.
 
Thank You! Thank You! Thank You!

Much obliged.


All's well that Ends!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top