September 12th, 2012, 10:01 AM
Search for data in a MSHFlexGrid
In my form, I have a MSHFlexGrid (fgdCompany) and a Search button.
What this search button should do is when I enter data into the InputBox, it should search for the entered data and highlight the row that the data was found in green in the MSHFlexGrid. My searching part works great.
But my problem is, if the entered data is not found, I want it to output a MsgBox saying "Record not found".
I can't get the piece of code for that function to work. Can anybody help me to get it right?
Here is the code I am using for the Search button.
Dim xString As String, xRow As Integer, xNext As Integer
cmdSaveNew.Enabled = False
x = InputBox("Enter Company Name : ", "Search")
If x = "" Then
MsgBox "No data entered"
txtSearch = x
xString = txtSearch
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
If xNext = fgdCompany.Rows Then
MsgBox "Record not found"
xRow = fgdCompany.Row
If xString = fgdCompany.TextMatrix(xRow, 1) Then
myRow = fgdCompany.Row
fgdCompany.TopRow = myRow
fgdCompany.RowSel = myRow
Me.fgdCompany.Row = myRow
For j = 0 To Me.fgdCompany.Cols - 1
Me.fgdCompany.Col = j
Me.fgdCompany.CellBackColor = vbGreen
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.