MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração


Participe do fórum, é rápido e fácil

MaximoAccess

Caro Usuário, antes de postar pela primeira vez, leia as regras do fórum.

https://www.maximoaccess.com/t48-regras-do-forum

Obrigado

Administração

MaximoAccess

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Dicas Ms Access, Exemplos Ms Access, Codigos VBA Ms Access, SQL Ms Access


2 participantes

    [Resolvido] Modificar código de busca por funcionário

    camilabzz
    camilabzz
    Novato
    Novato


    Respeito às regras : Respeito às Regras 100%

    Sexo : Feminino
    Localização : Brasil
    Mensagens : 40
    Registrado : 15/10/2012

    [Resolvido] Modificar código de busca por funcionário Empty [Resolvido] Modificar código de busca por funcionário

    Mensagem  camilabzz 9/11/2012, 20:01

    Olá,

    Eu criei em um form de funcionários um campo de busca com uma caixa de texto para o colocar o nome do funcionario, e um botão de buscar.
    Adaptei o código abaixo para o meu sistema, mas ele só busca se eu digitar o nome completo do funcionário, se eu quiser pesquisar somente pelo primeiro nome não funciona. Como posso modificá-lo para que isso seja possível?

    Private Sub cmdSearch_Click()
    Dim strStudentRef As String
    Dim strSearch As String

    'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
    MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
    Me![txtSearch].SetFocus
    Exit Sub
    End If
    '---------------------------------------------------------------

    'Performs the search using value entered into txtSearch
    'and evaluates this against values in strStudentID

    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("strStudentID")
    DoCmd.FindRecord Me!txtSearch


    strStudentID.SetFocus
    strStudentRef = strStudentID.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text

    'If matching record found sets focus in strStudentID and shows msgbox
    'and clears search control

    If strStudentRef = strSearch Then
    MsgBox "Match Found For: " & strSearch, , "Congratulations!"
    strStudentID.SetFocus
    txtSearch = ""

    'If value not found sets focus back to txtSearch and shows msgbox
    Else
    MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
    , "Invalid Search Criterion!"
    txtSearch.SetFocus
    End If
    End Sub


    Última edição por camilabzz em 14/11/2012, 16:34, editado 1 vez(es)
    Alexandre Neves
    Alexandre Neves
    Moderador Global
    Moderador Global


    Respeito às regras : Respeito às Regras 100%

    Sexo : Masculino
    Localização : Portugal
    Mensagens : 8449
    Registrado : 05/11/2009

    [Resolvido] Modificar código de busca por funcionário Empty Re: [Resolvido] Modificar código de busca por funcionário

    Mensagem  Alexandre Neves 9/11/2012, 22:11

    Boa noite, camila
    Private Sub cmdSearch_Click()
    Dim strStudentRef As String
    Dim strSearch As String

    'Check txtSearch for Null value or Nill Entry first.

    If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
    MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!"
    Me![txtSearch].SetFocus
    Exit Sub
    End If
    '---------------------------------------------------------------

    'Performs the search using value entered into txtSearch
    'and evaluates this against values in strStudentID

    DoCmd.ShowAllRecords
    DoCmd.GoToControl ("strStudentID")
    DoCmd.FindRecord "*" & Me!txtSearch & "*"

    strStudentID.SetFocus
    strStudentRef = strStudentID.Text
    txtSearch.SetFocus
    strSearch = txtSearch.Text

    'If matching record found sets focus in strStudentID and shows msgbox
    'and clears search control

    If strStudentRef = strSearch Then
    MsgBox "Match Found For: " & strSearch, , "Congratulations!"
    strStudentID.SetFocus
    txtSearch = ""

    'If value not found sets focus back to txtSearch and shows msgbox
    Else
    MsgBox "Match Not Found For: " & strSearch & " - Please Try Again.", _
    , "Invalid Search Criterion!"
    txtSearch.SetFocus
    End If
    End Sub


    .................................................................................
    Access 2010. Mande bd que dê para testar (indique a versão). Não peça para fazer o que já tem feito. Dê todos os detalhes.
    Não coloquem entraves como senhas, esconder controlos, etc. Disponibilizem o mais limpo possível
    Só respondo a mensagens privadas, se forem de assunto privado; às outras não respondo.
    Quem trabalha e mata a fome não come o pão de ninguém; mas quem não trabalha e come, come sempre o pão de alguém. António Aleixo

      Data/hora atual: 29/4/2024, 12:54