-
September 12th, 2012, 09:01 AM
#1
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.
Code:
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"
Exit Sub
Else
txtSearch = x
End If
xString = txtSearch
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
If xNext = fgdCompany.Rows Then
MsgBox "Record not found"
Exit Sub
End If
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
Next j
Exit For
End If
Next xNext
-
September 12th, 2012, 09:09 AM
#2
Re: Search for data in a MSHFlexGrid
Simply dim a boolean variable at the top of your code which will be false by default.
In your search routine set this variable to True if a match is found
At the bottom after the search loop is complete check the value of the variable and if false show your message
Always use [code][/code] tags when posting code.
-
September 12th, 2012, 10:03 AM
#3
Re: Search for data in a MSHFlexGrid
Originally Posted by DataMiser
Simply dim a boolean variable at the top of your code which will be false by default.
In your search routine set this variable to True if a match is found
At the bottom after the search loop is complete check the value of the variable and if false show your message
I tried that but it didn't work. Can you please give me the code for it..... I would greatly appreciate the help!!!
-
September 12th, 2012, 12:06 PM
#4
Re: Search for data in a MSHFlexGrid
Show the code where you tried it and explain what you mean by didn't work
Always use [code][/code] tags when posting code.
-
September 17th, 2012, 07:54 AM
#5
Re: Search for data in a MSHFlexGrid
I think this little piece of code might cause trouble:
Code:
For xNext = 0 To fgdCompany.Rows
fgdCompany.Row = xNext
If xNext = fgdCompany.Rows Then
MsgBox "Record not found"
Exit Sub
End If
...
You go For xNext=0 To fgdCompany.Rows.
Then you set fgdCompanyRow = xNext.
In case xNext has become fgdCompany.Rows caused by not finding a match, this will cause an error.
The maximum number for fgdCompanyRow is fgdCompanyRows-1.
So try to run your loop From xNext = 0 To fgdCompany.Rows - 1
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|