Jump to content

Recommended Posts

Posted

Olá a todos! Por favor alguem me pode ajudar .....  :bye2:

Estou a trabalhar numa bd em access 2000 e preciso  de fazer pesquisa multipla por varias combos... O cliente "x" k esta na area "y" cujo processo esta "Aberto"....

Preciso disso com urgencia, tou estagiando... se puderem nem k seja mandar exemplos.....

Obrigada

Posted

Olá Bom dia!

Tenho assim:

‘PESQUISA POR AREA DE NEGOCIO(uma combobox(“área”) que carrega as areas a partir da tabela Área de negocio):
Private Sub area_Change()
Dim s As String
Forms![mapa de processos].RecordSource = "mapa2"

s = "SELECT NºProcesso, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE AreaNegocio LIKE '" & Me!area.Value & "'"
Me.RecordSource = s
'Me.Refresh

End Sub

‘ UMA COMBO E UMA CAIXA DE TEXTO, DENTRO DA COMBO(campo) TEMOS NOME DE CLIENTE, CONTACTO E ASSUNTO NÃO OFICIAL:
Private Sub campo_Change()

End Sub

Private Sub Comando54_Click()
Dim sql As String
Dim criterio As String

Forms![mapa de processos].RecordSource = "mapa2"

criterio = campo.Value

Select Case campo

Case "Nome de cliente"
sql = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE Nome LIKE '%" & Me!TextoPesq.Value & "%'"
Me.RecordSource = sql
'Me.Refresh

Case "Contacto"
sql = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE Contacto LIKE '%" & Me!TextoPesq.Value & "%'"
Me.RecordSource = sql
'Me.Refresh

Case "Assunto não oficial"
sql = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE AssuntoNOficial LIKE '%" & Me!TextoPesq.Value & "%'"
Me.RecordSource = sql
'Me.Refresh

End Select
End Sub

'FILTRO POR ESTADO DE ENTREGA/MONTAGEM (COMBOBOX):

Private Sub entrega_montagem_Change()
Dim x As String
Forms![mapa de processos].RecordSource = "mapa2"


x = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE [Estado Entrega_montagem] LIKE '" & Me!entrega_montagem.Value & "'"
Me.RecordSource = x
'Me.Refresh

End Sub

'FILTRO POR SITUAÇÃO DO PROCESSO
Private Sub situacao_Change()
Dim exp As String
Forms![mapa de processos].RecordSource = "mapa2"

exp = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2 WHERE Situação_processo LIKE '" & Me!situacao.Value & "'"
Me.RecordSource = exp
'Me.Refresh

End Sub

' MOSTRAR TODOS OS REGISTOS E LIMPAR FILTROS
Private Sub tudo_Click()
Dim sql As String

Forms![mapa de processos].RecordSource = "mapa2"

TextoPesq = ""
campo = ""
situacao = ""
entrega_montagem = ""
area = ""

sql = "SELECT Processo_n, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2"
Me.RecordSource = sql
Me.Refresh
End Sub

E agora preciso de uma string para juntar todos esses filtros num... Axo eu... ?

Obrigada...

Posted

Olhem atraves dum exemplo k encontrei na Net :

Function fGetWhere() as String

Dim strWhere as String 

If nz(Len(Me.area),0)>0 Then

  strWhere = "AreaNegocio = " & Me.area.value

End If

 

If nz(Len(Me.entrega_montagem),0)>0 Then

  strWhere = fGetAnd(strWhere) & "[Estado Entrega_montagem] = " & Me. entrega_montagem.value

End If

If nz(Len(Me.situacao),0)>0 Then

  strWhere = fGetAnd(strWhere) & "[situação_processo] = " & Me. situacao.value

End If

If nz(Len(Me.campo),0)>0 Then

Select case campo

Case “Nome de cliente”

  strWhere = fGetAnd(strWhere) & "Nome = " & Me.TextoPesq.value

Case “Contacto”

  strWhere = fGetAnd(strWhere) & "Contacto = " & Me.TextoPesq.value

Case “Assunto não oficial”

  strWhere = fGetAnd(strWhere) & " AssuntoNOficial = " & Me.TextoPesq.value

End If

 

'wash, rinse, repeat for each control

 

If Nz(Len(strWhere),0)>0 Then

  fGetWhere = "WHERE " & strWhere

End If

End Function

Function fGetAnd(sStringToCheck) as String

  If Nz(Len(sStringToCheck),0)>0 Then

    fGetAnd = sStringToCheck & " AND "

  else

    fGetAnd = ""

  End If

End Function

 

Function fSetRecordSource()

Dim strSQL as String

 

strSQL = "SELECT NºProcesso, UltimaVersao, Nome, Contacto, AreaNegocio, Situação_processo, [Data Entrega_Montagem], Prazo_limite_ent_mont, [Estado Entrega_montagem], AssuntoNOficial FROM mapa2" & fGetWhere

 

Me.RecordSource = strSQL

End Function

e agora onde as utilizo???? :wallbash:

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.