这个是能检查数据重复!但如果再次双击时无论数据是否重复它都提示"重复"!请老师指点下!!谢谢!
Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
tmpRow = MSFlexGrid1.Row
tmpCol = MSFlexGrid1.Col
MSFlexGrid1.Row = gRow
MSFlexGrid1.Col = gCol If gCol = 1 Then
For c = 1 To MSFlexGrid1.Rows - 1
If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then
MsgBox "重复", 48, "错误"
Text1.Text = ""
End If
Next c
MSFlexGrid1.Text = Text1.Text
End If Text1.SelStart = 0
Text1.Visible = False
Exit Sub
Errorhandler:
Exit Sub
End Sub
Private Sub Text1_LostFocus()
Dim tmpRow As Integer
Dim tmpCol As Integer
tmpRow = MSFlexGrid1.Row
tmpCol = MSFlexGrid1.Col
MSFlexGrid1.Row = gRow
MSFlexGrid1.Col = gCol If gCol = 1 Then
For c = 1 To MSFlexGrid1.Rows - 1
If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then
MsgBox "重复", 48, "错误"
Text1.Text = ""
End If
Next c
MSFlexGrid1.Text = Text1.Text
End If Text1.SelStart = 0
Text1.Visible = False
Exit Sub
Errorhandler:
Exit Sub
End Sub
你可以选择单步调试啊。
在If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then 设个断点,每次运行的时候看看里面的值有什么变化没,就知道为什么老是执行 MsgBox "重复", 48, "错误" 了
MSFlexGrid1.Col = gCol
debug.print "Text1.Text",text1.text'加上这句运行,到立即窗口看看输出结果 怀疑你上面两句已经改变了text1的内容 If gCol = 1 Then
For c = 1 To MSFlexGrid1.Rows - 1
If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then
MsgBox "重复", 48, "错误"
Text1.Text = ""
End If
Next c
刚试了还是跟前面的一样哦!!我这个是在加上检查重复的数据这个才会出现不正常的!
If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then
MsgBox "重复", 48, "错误"
Text1.Text = ""
End If
Next c
Private Sub MSFlexGrid1_DblClick()
If MSFlexGrid1.Rows = 1 Then Exit Sub
Text1.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
Text1.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
gRow = MSFlexGrid1.Row
gCol = MSFlexGrid1.Col
If gCol <> 1 Then Exit Sub
Text1.Width = MSFlexGrid1.CellWidth
Text1.Height = MSFlexGrid1.CellHeight
Text1.Text = MSFlexGrid1.Text
Text1.Visible = True
Text1.ZOrder 0
Text1.SetFocus
For c = 1 To MSFlexGrid1.Rows - 1
If Text1.Text = MSFlexGrid1.TextMatrix(c, 1) And Text1.Text <> "" Then
''''MsgBox "重复", 48, "错误"
'''''Text1.Text = ""
debug.? "重复行:";c,"TextMatrix:";MSFlexGrid1.TextMatrix(c, 1),"Text1.text";Text1.text
else
debug.? "行:";c,"TextMatrix:";MSFlexGrid1.TextMatrix(c, 1)
End If
Next c 运行看看到底哪行的问题吧
如果你原来弹出msgbox,现在立即窗口肯定有输出
除非你的代码别的地方还有 MsgBox "重复", 48, "错误" 这样的语句