I have made me a very nice search form - in fact I think I saw the idea in here, but unfortunately I can't find it again ;-((
It's a form with a textbox in the form footer and as you type the shown records changes to only show records with the text in the search field - that's what search forms do - right ?
I experienced that the search field CAN'T take a SPACE - the form just flickers and the search field stays the same (as before pressing the space) - I can't find WHERE the space key is suppressed.
Here are the KeyDown event and I have KeyPreview on the form for moving the focus from record to record with Ctrl+PdDn/Up:
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyEscape
If Me.Dirty Then Me.Undo ' Cancel any changes
DoCmd.Close acForm, Me.Form.Name
Case vbKeyPageUp
If Shift = acCtrlMask Then
On Error Resume Next
DoCmd.GoToRecord Record:=acPrevious
On Error GoTo 0
End If
Case vbKeyPageDown
If Shift = acCtrlMask Then
On Error Resume Next
DoCmd.GoToRecord Record:=acNext
On Error GoTo 0
End If
Case vbKeyReturn
Form_Close Me, ""
End Select
End Sub
And here are the Change event for the search field:
Code:
Private Sub txtSearchFor_Change()
Me.Requery
Me.txtSearchFor.SetFocus
If Me.Recordset.RecordCount > 0 And Not IsNull(Len(Me.txtSearchFor)) Then
Me.txtSearchFor.SelStart = Len(Me.txtSearchFor)
End If
End Sub
All the 'filtering' is done in the query with a criteria like this ON ALL THE FIELDS shown in the search form:
Like "*" & [forms]![PERSON Generelt opslag på personer]![txtSearchFor] & "*"
How can I get this to accept a space key too - in fact I can't see why it shouldn't !
Any ideas ?