Expand|Select|Wrap|Line Numbers
- FN_buffer.SelStart = Len(FN_input)
Expand|Select|Wrap|Line Numbers
- Me.FN_input.Value = Me.FN_buffer.Text
MS Access 2016 continuous form bound to a query. Unbound textbox controls in the header, the _input control is a criteria for the query. The _input control is 'locked,' the _buffer control is not.
It transfers the first two characters to the _input control before it begins failing.
Expand|Select|Wrap|Line Numbers
- Private Sub FN_buffer_KeyUp(KeyCode As Integer, Shift As Integer)
- 'This subroutine institutes a live-action query on every character entered
- 'this brings up on-the-fly match results as the user types each character.
- 'Only numerical, alphanumerical, Space, or backspace characters count for this action.
- 'This code is for the (unbound) [textbox]_buffer control, the 'hidden' [textbox]_input
- ' control is the actual (unbound) control coded as search criteria the query.
- 'The [textbox]_input control is only filled in (and cleared) using this code.
- 'Note that the delete key actions do not fire here, and therefore
- ' they will have unintended consequences, so should be avoided.
- On Error GoTo Err_Handler
- If (Not IsMissing(KeyCode)) Then
- If (KeyCode > 47 And KeyCode < 91) Or KeyCode = vbSpace Or KeyCode = vbKeyBack Then
- ' If key is numerical, alphanumerical, Space, or backspace then transfer it to live query
- 'the following code prevents #2185 errors with null .Text value of this control
- MsgBox ("FN_charCount = " & FN_charCount)
- If KeyCode = vbKeyBack And FN_charCount > 0 Then
- FN_charCount = FN_charCount - 1 'decrement count on backspace key (if not zero length previously)
- MsgBox ("Decrement fired")
- Else
- FN_charCount = FN_charCount + 1 'count characters in text
- MsgBox ("Increment fired")
- MsgBox ("FN_charCount = " & FN_charCount)
- End If
- If FN_charCount > 0 Then 'Null .Text property throws error
- Me.FN_input.Value = Me.FN_buffer.Text
- 'move the current typed text to (hidden) query control textbox
- MsgBox ("Text move fired")
- Else
- MsgBox ("About to clear search string")
- Me.FN_input.Value = vbNullString
- 'if text calculates as Null, make input control value Null also
- MsgBox ("Search string should be cleared")
- End If
- MsgBox ("Requery imminent")
- Me.Requery 'query in real-time on-the-fly
- MsgBox ("Requery occurred")
- Me.FN_buffer.SetFocus 'return cursor to control (textbox)
- MsgBox ("Focus occurred")
- If FN_charCount > 0 Then 'Null selection properties throws #2185 errors
- Me.FN_buffer.SelLength = 0 'unselect text and...
- Me.FN_buffer.SelStart = Len(FN_input)
- 'set cursor to end ready for the next char
- MsgBox ("Deselected text in textbox")
- End If
- MsgBox ("FN_charCount = " & FN_charCount)
- End If
- End If
- ExitSub:
- Exit Sub
- Err_Handler:
- MsgBox ("Error #" & Err.Number & ": " & Err.Description)
- Resume ExitSub
- End Sub