by Mostafa El-Awady (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 30th August 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code will find any wanted string or part of any string in a database with highlighting the found string, It create Find button and Find
'***\\* Mostafa El Awady *//***
'****\\******************//****
'****//******************\\****
'***//**For any Questions*\\***
'**//**[email protected]***\\**
'**--------------------------**
' Create 3 textboxes
' Create variable called A as integer
' Create 2 timers set Interval = 1 and Enabled = False
' Create 2 command buttons one for find and the other for find next
'******************************************************************************
'**********************Put the following code in the form**********************
'******************************************************************************
Private Sub Command1_Click() ' The find button
DataEnvironment.rsCommand1.MoveFirst
Timer1.Enabled = True
End sub
Private Sub Command2_Click() ' The find Next button
Timer2.Enabled = True
End sub
Private Sub Timer1_Timer()
A = InStr(Text1.Text, Text2.Text)
' Text1 refers to the textbox joined to the data field you want to search in
' Text2 refers to the textbox that contain to string wanted to be found
Text3.Text = A
' Text3 will be unvisible, it is used to save required data
If Text3.Text <> 0 Then
Text1.SetFocus
Text1.SelStart = CInt(Text3.Text - 1)
Text1.SelLength = Len(Text2.Text)
Text3.Text = 0
Timer1.Enabled = False
Exit Sub
End If
DataEnvironment.rsCommand1.MoveNext
If DataEnvironment.rsCommand1.EOF Then
MsgBox "Subject not found", vbExclamation, "Find Result"
Timer1.Enabled = False
DataEnvironment.rsCommand1.MoveFirst
End If
End sub
Private Sub Timer2_Timer()
DataEnvironment.rsCommand1.MoveNext
if DataEnvironment.rsCommand1.EOF Then
MsgBox "Subject not found", vbExclamation, "Find Result"
Timer1.Enabled = False
DataEnvironment.rsCommand1.MoveFirst
End If
A = InStr(Text1.Text, Text2.Text)
' Text1 refers to the textbox joined to the data field you want to search in
' Text2 refers to the textbox that contain to string wanted to be found
Text3.Text = A
' Text3 will be unvisible, it is used to save required data
If Text3.Text <> 0 Then
Text1.SetFocus
Text1.SelStart = CInt(Text3.Text - 1)
Text1.SelLength = Len(Text2.Text)
Text3.Text = 0
Timer1.Enabled = False
Exit Sub
End If
End sub
No comments have been posted about This code will find any wanted string or part of any string in a database with highlighting the fou. Why not be the first to post a comment about This code will find any wanted string or part of any string in a database with highlighting the fou.