Hi All,
I have a form that has a mshflexgrid with data populated from ms access database. A combobox with client names populated from my access database during form load. All is working fine here.
My problem is:
1) to set the focus of the cursor to the record selected from the combobox and
2) highlight the record searched in the mshflexgrid
3) set the color back to default ie vbWhite when another record is searched from the combobox
I have a code here but it is not working the way I intend to.
Dim r As Integer
Dim c As String
For r = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = r
MSHFlexGrid1.Col = 3
If MSHFlexGrid1.Text = cboSearch.Text Then
MsgBox " Record Found"
With MSHFlexGrid1
.Col = .FixedCols
.ColSel = .Cols - 1
.CellBackColor = vbGreen
.ColSel = .Col
.RowSel = .Row
End With
Exit Sub
Else
MsgBox " Record NOT Found"
End If
Next r
What it's doing is that on clicking a client name in the combobox, it firstly displays 'Msgbox "Record NOT Found"' and sets the focus on the 2nd row instead of positioning the cursor on the first row in column 3 (column where the clients names are stored). The cursor then moves from the first record to the second and so forth upon clicking the OK button of the Msgbox "Record NOT Found" which appears when the cursor loops through each records. When it reaches the record specified in the combobox then it does what I intends it to do and the msgbox also stops showing up.
What I want is, when the user clicks a client name in the cboSearch (combobox) it should automatically highlight that particular client name in the mshflexgrid.
Could you please assist me in getting this problem solved.
Thank you in advance for your time and consideration.
I have a form that has a mshflexgrid with data populated from ms access database. A combobox with client names populated from my access database during form load. All is working fine here.
My problem is:
1) to set the focus of the cursor to the record selected from the combobox and
2) highlight the record searched in the mshflexgrid
3) set the color back to default ie vbWhite when another record is searched from the combobox
I have a code here but it is not working the way I intend to.
Dim r As Integer
Dim c As String
For r = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = r
MSHFlexGrid1.Col = 3
If MSHFlexGrid1.Text = cboSearch.Text Then
MsgBox " Record Found"
With MSHFlexGrid1
.Col = .FixedCols
.ColSel = .Cols - 1
.CellBackColor = vbGreen
.ColSel = .Col
.RowSel = .Row
End With
Exit Sub
Else
MsgBox " Record NOT Found"
End If
Next r
What it's doing is that on clicking a client name in the combobox, it firstly displays 'Msgbox "Record NOT Found"' and sets the focus on the 2nd row instead of positioning the cursor on the first row in column 3 (column where the clients names are stored). The cursor then moves from the first record to the second and so forth upon clicking the OK button of the Msgbox "Record NOT Found" which appears when the cursor loops through each records. When it reaches the record specified in the combobox then it does what I intends it to do and the msgbox also stops showing up.
What I want is, when the user clicks a client name in the cboSearch (combobox) it should automatically highlight that particular client name in the mshflexgrid.
Could you please assist me in getting this problem solved.
Thank you in advance for your time and consideration.