Results 1 to 22 of 22

Thread: Search for data in a MSHFlexGrid

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    41

    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
    Last edited by Skate Bart; Sep 12th, 2012 at 09:03 AM.

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
  •  



Click Here to Expand Forum to Full Width