How to highlight MSFlexGrid row?
Hi,
Im working with a form where all the item details are placed in MSFlexGrid and on clicking the Save button the code verifies the MSFlexgrid's item number column to avoid duplicate entries.
Now, what I want is to highlight with red all the duplicate rows at once when Save is clicked, i.e, it should show multiple entries in red.
My code works as:
1. when Save is clicked it highlights only one row at a time
2. it gets highlighted only when user clicks the row
3. every row gets highlighted in red on clicking the msflexgrid's row making it indistinguishable with the duplicate ones unless Save is clicked again.
Here is my code, could anyone help me with this?
Code:
Private Sub cmdSave_Click()
'open Item table
Set myrs2 = New ADODB.Recordset
myrs2.Open "Item", mycon, adOpenKeyset, adLockPessimistic, adCmdTable
'verify item numer for duplicate entry
Dim x As Integer
For x = 1 To MSFlexGrid1.Rows - 1
If MSFlexGrid1.TextMatrix(x, 0) = myrs2.Fields("ItemNumber") Then
With MSFlexGrid1
MsgBox "Duplicate Item Number(s) found! Please edit or remove the corresponding Item details.", vbOKOnly + vbCritical, "Duplicate Entry"
.Row = x
.Col = 0
.BackColorSel = vbRed
End With
End If
Next
end Sub
Re: How to highlight MSFlexGrid row?
See "how to use ms flexgrid" link in my signature.
Re: How to highlight MSFlexGrid row?
Im sorry, but could you brief it out. The link has puzzled me further.
Re: How to highlight MSFlexGrid row?
Did you notice post #4 in the thread linked by RB?
Re: How to highlight MSFlexGrid row?
ok i finally tried and got it as desired but only one point is left. It does not highlight only the duplicate fields instead it highlights all the rows of MSFlexGrid.
Could anyone correct me as to what is going wrong? Here is the modified code:
Code:
'open Item table
Set myrs2 = New ADODB.Recordset
myrs2.Open "Item", mycon, adOpenKeyset, adLockPessimistic, adCmdTable
'verify item numer for duplicate entry
Dim z As Integer
For z = 1 To MSFlexGrid1.Rows - 1
If MSFlexGrid1.TextMatrix(z, 0) = myrs2.Fields("ItemNumber") Then
With MSFlexGrid1
MsgBox "Duplicate Item Number(s) found! Please edit or remove the corresponding Item details.", vbOKOnly + vbCritical, "Duplicate Entry"
Dim y%, x%
For x = 1 To .Rows - 1
For y = 1 To .Cols - 1
.Row = x
.Col = y
.CellBackColor = vbRed
Next y
Next x
End With
Exit Sub
End If
'Exit Sub
Next z
Re: How to highlight MSFlexGrid row?
Of course you need to put logic to determine the duplicate fields.