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:
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