Combo box like function with out combo box

  • Thread starter Thread starter knave
  • Start date Start date
K

knave

Have seen data entry that allows users to do a combo like function from
the fields on continous form. Example: User selects a field on the
form, starts typing and the fields on the form move to the closest
character match while user is typing.

Been trying to duplicate this function in Access and VB - has anyone
seen code for this?
 
Yes this works fine, little modification and got exactly what is
needed.
Thank You Duane - oh originator of the demo code.

Now the user does not need to use any ComboBoxs to move to a record.
Now I just have to figure out how to make the display in the fields
move with the characters typed.

Code looked like this:
-------------------------------------------------------------------------------------------------------------------------------------
Defined some modual vars to have local scope
Dim strFind As String
Dim datLastKeyPress As Variant

Then added the following to KeyPress on a field
Private Sub Name_KeyPress(KeyAscii As Integer)
Dim strChr As String
strChr = Chr(KeyAscii)
If DateDiff("S", datLastKeyPress, Now) > 3 Then
strFind = strChr
Else
strFind = strFind & strChr
End If

DoCmd.FindRecord strFind, acStart, , , , , True
datLastKeyPress = Now
End Sub

Added the following to clear strFind if user clicks the mouse somewere
else.

Private Sub DeptName_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
strFind = ""
End Sub
------------------------------------------------------------------------------------------------------------------------------------
 
I'm not sure exactly what you mean by "Now I just have to figure out how to
make the display in the fields move with the characters typed". The demo
used a continuous subform. Do you need to use a single form view?
 
This is for a continous form. The display of field information, has
user types, has the complete text highlighted. This does not show the
user what letters they have already typed. i.e. field with "abcdefg"
in it would show all letters highlighted even after user has typed "ab
or "abc". This visual could confuse users.
 
You might be able to use SelText in the KeyPress event with Len(strFind) to
highlight the appropriate characters.
 
Yes, that worked, thanks.

Final Sub code now looks like this, and works verry well.

Private Sub DeptName_KeyPress(KeyAscii As Integer)
Dim strChr As String
Dim intWhere As Integer
' Doing the find process
strChr = Chr(KeyAscii)
If DateDiff("S", datLastKeyPress, Now) > 3 Then
strFind = strChr
Else
strFind = strFind & strChr
End If
' Going to match record if one exists
' Standing still if one does not
DoCmd.FindRecord strFind, acStart, , , , , True
datLastKeyPress = Now
' Moving/Highlighting characters pressed
With Me!DeptName
' Find if string in text.
intWhere = InStr(.Text, strFind)
.SelStart = 0 ' Highlight from first character
If intWhere Then ' set highlight if exists
.SelLength = Len(strFind)
Else ' clear highlight if not exists
.SelLength = 0
End If
End With
End Sub
 
Just thinking - how to make this more generic. All it needs is a way to
know what form you are on and what field has the focus.
Then this becomes a single public function for any field needing this
type of function and makes for shorter code to maintain.

Just don't know how to get the what form you are on and what field has
the focus from inside the Sub?
Is it better to pass the information or to get it when inside the Sub.

Outline of processing:
Key Press causes event Private Sub XXXXXX_Keypress(KeyAscii As
Integer) to occur
This calles Generic_Keypress( KeyAscii)
Generic_Keypress then does the processing.
or
Key Press causes event Private Sub XXXXXX_Keypress(KeyAscii As
Integer) to occur
This calles Generic_Keypress( KeyAscii, CtrlFieldInfo)
Generic_Keypress then does the processing.
 
I think you can use ActiveScreen or ActiveForm or ActiveControl or something
like that. I'm not sure how generic you could make this. There are some
generic date/calendar functions in the demo file (I think).
 
Found a problem with keypress event - when user tabs into a field with
this function the keypress does not trigger the event...?????

Will try the Actives and let you know.....
 
Back
Top