Text box the searches with every added letter (1 Viewer)

Saladsnake

New member
Local time
Today, 03:13
Joined
Aug 5, 2014
Messages
5
I'm trying to add a search function the searches with ever letter I add to the string in the search box. if the string is not in the recordset then vbred the textbox.




Here's my code:
Code:
Private Sub txtGroupNr_KeyPress(KeyAscii As Integer)
    Set RstRecSet = Nothing
    Set db = CurrentDb
    
 On Error Resume Next
If IsNull(txtGroupNr) Or txtGroupNr = "" Then
'        MsgBox "Please enter a Group Number to use as the search criteria", _
'        vbExclamation, _
'        "Missing Group Number"
Me.txtGroupName.BackColor = vbRed
        Forms!frmGroupHeader!txtGroupNr.SetFocus
'    ElseIf Len(txtSearchICN.Value) < 14 Then
'        MsgBox "The ICN Number you entered is too short, please enter one that is 14 digits long", _
'        vbExclamation, _
'        "ICN Number Length too short"
'
'        Forms!frmMCRWF2!txtSearchICN.SetFocus
'    ElseIf Len(txtSearchICN.Value) > 14 Then
'        MsgBox "The ICN Number you entered is too long, please enter one that is only 14 digits long", _
'        vbExclamation, _
'        "ICN Number Length too long"
'        Forms!frmMCRWFForm2!txtSearchICN.SetFocus
    Else
        strSearchICN = txtGroupNr
        Set db = CurrentDb
        Me.txtGroupName.BackColor = vbWhite
        Set RstRecSet = db.OpenRecordset("Select * from tblGroupHeader Where GroupNum Like '" & strSearchICN & "';", dbOpenDynaset)
        RstRecSet.MoveLast
        intMaxCount = RstRecSet.RecordCount
        RstRecSet.MoveFirst
      ' Exit Sub
   End If
     
     If RstRecSet.EOF Then
''         MsgBox "There were no records found relating to that ICN Number, please try another.", _
''         vbExclamation, _
''         "No Record Found"
        Me.txtGroupName.BackColor = vbRed
        Forms!frmGroupHeader!txtGroupNr.SetFocus

    
    Else
    Call DisplayFields
    
    End If
End Sub
 

JHB

Have been here a while
Local time
Today, 12:13
Joined
Jun 17, 2012
Messages
7,732
And what is the problem, you didn't write it?
Comment out the "On Error Resume Next" and see what happen.
 

Saladsnake

New member
Local time
Today, 03:13
Joined
Aug 5, 2014
Messages
5
And what is the problem, you didn't write it?
Comment out the "On Error Resume Next" and see what happen.

It's being reperposed. it's mine.. The issue is that when I type "4" for example it'll bring up the closest record to 4. however, if i try to continue to type to narrow it down snd yype another number lets say "3" it'll delete the 4 and put a 3 in its place. I want it to go from searching 4 to searching 43.
 

MarkK

bit cruncher
Local time
Today, 03:13
Joined
Mar 17, 2004
Messages
8,181
I would use the Change event of the textbox, and read its .Text property, because the .Value doesn't change until AfterUpdate.

And some operations may remain unavailable while there is a pending update in the control. Some operations may force the update in the control to complete, and that might move your insertion point back to the start of the field, and so on, for instance, you probably can't open a MsgBox between keystrokes. Or more accurately, you can open one, but that will probably force the pending update in the control to complete, and move the insertion point to the first position in the control.

So you might need to add a control to your form and show messaging in that control, instead of using MsgBox, which is a new modal window.

Hope this helps,
 

Users who are viewing this thread

Top Bottom