-
Background: In the MSFlexGrid application that I am writing, I have a For...Next search loop that searches every cell for a string input by the user. When there is a "hit" the record that contains that string is displayed in another MSFlexGrid.
Problem: Records in the database often contain several instances of the search string, so these records are displayed several times. I created a variable strComp into which I store the record that has just been found. I would like to compare it with the current search string variable strRow and if they match, exit out of the loop so that there is only one copy of each record displayed instead of multiple copies. What is the proper syntax for such an expression? VB6 won't accept anything I've tried.
Thanks,
-Bob Smythe
-
You can create a collection to hold the records that you find. This example uses text from a textbox, but you can modify it to use the data found in your grid.
Code:
Option Explicit
Public MyCollection As New Collection
Private Sub Command1_Click()
Dim bFound As Boolean
Dim strDummy As String
On Error Resume Next
strDummy = MyCollection.Item(Text1.Text)
bFound = (Err = 0)
If bFound Then
MsgBox "Duplicate"
Err.Clear
Else
MyCollection.Add Text1.Text, Text1.Text
End If
End Sub
BTW if you are not familiar with collections, the data following the .Add is the Item followed by the Key and in this case we've made them the same but they don't have to be.