vb msflexgrid控件防止录重复数据解决思路

vb msflexgrid控件防止录重复数据
我有一个msflexgrid控件,现在做成录入表单. 现在不能防止录入相同数据。
例如数据如下:
1 2 3 4 5
-----------------------------
A1 080901 80 90 1
A1 080902 50 50 1
A1 080901 70 70 1
.........
------------------------------
合计 3 
------------------------------  
现在我想判断在第1列和第2列是否存在相同的数据.(以上的数据中的第1行(A1 080901)和第3行的(A1 080901)相同)
请问如何判断?
请各位大侠帮忙。
dim s As Integer
For s = 1 To Val(MSFlexGrid2.TextMatrix(0, 5))
if Trim(MSFlexGrid1.TextMatrix(s, 1))=? and Trim(MSFlexGrid1.TextMatrix(s, 2))=? then
msgobx"......"
exit sub
end if
Next s

------解决方案--------------------
前台,双重遍历。
for i = .fixedrow to 5
 for l = i to 5
if textmatrix(i,0) = textmatrix(l,0) and textmatrix(i,1) = textmatrix(l,1) then
msgbox "..."
goto duplicate
endif
 next
next

Duplicate:

后台,在1 和 2 列 上加unique index。
------解决方案--------------------
录入时检查

Private Sub MSFlexGrid1_RowColChange()
Dim i As Long, ret As Integer

If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) > "" Then
For i = 1 To MSFlexGrid1.Row - 1
If MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1) = MSFlexGrid1.TextMatrix(i, 1) Then
ret = MsgBox("重复的数据", vbInformation + vbRetryCancel)
If ret = vbCancel Then
MSFlexGrid1.RemoveItem MSFlexGrid1.Row
Exit Sub
End If
MSFlexGrid1.Col = 1
Exit For
End If
Next i
End If
End Sub