Carlos posto aqui novamente o exemplo, o fórum do macoratti, engole muita coisa:
Coloque no formulário:
Um controle DATA
Um ComboBox
Dois TextBox
Um MsFlexGrid
Nome dos Controles:
DATA = dtaVENDEDOR
COMBO = cboORDEM
Text1 = txtPROCURA
Text2 = txtCODVEN
MsFlex = msfVENDEDOR
Configue o controle DATA e o Text(txtCODVEN) invisiveis.
Na propriedade DataSource do Flex aponte para o controle dtaVENDEDOR.
Em declarações do formulário
Dim sSQL As String
Dim sORDEM As String
Dim sPROC As String
Dim sFORMAT As String
Private Sub Form_Load()
dtaVENDEDOR.DataBaseName = "NOME CAMINHO DO SEU BANCO"
PROCURA
End Sub
Private Sub msfVENDEDOR_EnterCell() ' repita para o evento Click do Flex
If dtaVENDEDOR.Recordset.RecordCount > 0 Then
txtCODVEN.Text = msfVENDEDOR.TextMatrix(msfVENDEDOR.RowSel, 0)
End If
End Sub
Private Sub txtPROCURA_GotFocus()
iTECLA = 0
End Sub
Private Sub txtPROCURA_KeyPress(TK As Integer)
If TK <> 8 And TK <> 13 And TK <> 32 Then
If iTECLA = 0 Then
txtPROCURA.Text = ""
End If
End If
iTECLA = 1
End Sub
Private Sub txtPROCURA_KeyUp(TK As Integer, Shift As Integer)
PROCURA
End Sub
Private Sub txtPROCURA_KeyDown(TK As Integer, Shift As Integer)
If TK = 13 Then
msfVENDEDOR.SetFocus
Exit Sub
End If
End Sub
Private Sub txtPROCURA_LostFocus()
PROCURA
End Sub
Private Function PROCURA()
dtaVENDEDOR.Enabled = True
dtaVENDEDOR.ReadOnly = False
sPROC = UCase$(txtPROCURA)
sORDEM = UCase$(cboORDEM.Text)
sSQL = "SELECT CODVEN,NOMEVEN,CPF,FONE,CELULAR FROM VENDEDOR"
If Len(Trim(sPROC)) > 0 Then
sSQL = sSQL & " WHERE "
Select Case sORDEM
Case "NOME DO VENDEDOR"
sSQL = sSQL & "NOMEVEN>='" & sPROC & "'"
Case "CÓDIGO DO VENDEDOR"
sSQL = sSQL & "CODVEN>='" & sPROC & "'"
Case Else
sSQL = sSQL & "NOMEVEN>='" & sPROC & "'"
End Select
Else
sSQL = sSQL & " ORDER BY "
Select Case sORDEM
Case "NOME DO VENDEDOR"
sSQL = sSQL & "NOMEVEN"
Case "CÓDIGO DO VENDEDOR"
sSQL = sSQL & "CODVEN"
Case Else
sSQL = sSQL & "NOMEVEN"
End Select
End If
dtaVENDEDOR.RecordSource = sSQL
dtaVENDEDOR.Refresh
msfVENDEDOR.Refresh
sFORMAT = "^CÓDIGO|NOME DO VENDEDOR|^C.P.F.|<TELEFONE|<CELULAR"
msfVENDEDOR.FormatString = sFORMAT
msFLEX
If dtaVENDEDOR.Recordset.RecordCount > 0 Then
txtCODVEN.Text = msfVENDEDOR.TextMatrix(1, 0)
End If
dtaVENDEDOR.Enabled = False
dtaVENDEDOR.ReadOnly = True
Exit Function
End Function
Private Function msFLEX()
msfVENDEDOR.ColWidth(0) = (800 * lWIDTH)
msfVENDEDOR.ColWidth(1) = (4500 * lWIDTH)
msfVENDEDOR.ColWidth(2) = (2000 * lWIDTH)
msfVENDEDOR.ColWidth(3) = (2000 * lWIDTH)
msfVENDEDOR.ColWidth(4) = (2000 * lWIDTH)
Exit Function
End Function
As variáveis lHEIGHT E lWIDTH, são variáveis públicas do Tipo Long, que representam a resolução do monitor, voce pode tirar isto.
A medida que o usuário vai digitando no txtPROCURA, o Flex vai rolando, e quando ele clicar no flex, ou digitar o enter(como quiser), para voce saber qual registro selecionado, voce identifica pelo valor txtCODVEN.Text, pois a medida que rola este valor vai mudando.
vlu//