Boa noite estou tentando pegar a primeira data e a última data de uma caixa de listagem depois de ser filtrada
- Anexos
exemploMarceloMarques_rev.zip
- Você não tem permissão para fazer download dos arquivos anexados.
- (392 Kb) Baixado 16 vez(es)
BrunoReis gosta desta mensagem
Public Function DFirstX(NomeCampo As Variant, nomeTabela As Variant, Optional filtro As String = "") As Variant
Dim RS As DAO.Recordset
Dim strSQL As String
strSQL = "Select first(" & NomeCampo & ") AS k FROM " & nomeTabela & IIf(filtro = "", ";", " WHERE " & filtro & ";")
Call fncAbreConexao(102030)
Set RS = Db.OpenRecordset(strSQL, 4)
DFirstX = RS!k
RS.Close
Set RS = Nothing
End Function
Public Function DLastX(NomeCampo As Variant, nomeTabela As Variant, Optional filtro As String = "") As Variant
Dim RS As DAO.Recordset
Dim strSQL As String
strSQL = "Select last(" & NomeCampo & ") AS k FROM " & nomeTabela & IIf(filtro = "", ";", " WHERE " & filtro & ";")
Call fncAbreConexao(102030)
Set RS = Db.OpenRecordset(strSQL, 4)
DLastX = RS!k
RS.Close
Set RS = Nothing
End Function
Private Sub AtualizarDatas()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sql As String
' Montar a consulta SQL diretamente no VBA
sql = "SELECT Min(cs_pesquisaCascata.Dt_Vencimento) AS DataInicial, Max(cs_pesquisaCascata.Dt_Vencimento) AS DataFinal " & _
"FROM cs_pesquisaCascata " & _
"WHERE ((cs_pesquisaCascata.NomeCliente) Like '" & Me!txtfornecedor & "*') " & _
"And ((cs_pesquisaCascata.Descricao) Like '" & Me!txtproduto & "*') " & _
"And ((cs_pesquisaCascata.TIPO_DESPESA) Like '" & Me!CBOtipodespesa & "*') " & _
"And ((Format([dt_vencimento],'mm')) Like '" & Me![cbomes Vencimento] & "*') " & _
"And ((Format([dt_vencimento],'yyyy')) Like '" & Me!cboAnoVencimento & "*') " & _
"And ((cs_pesquisaCascata.Quitar) Like '" & Me!txtsituacao & "*');"
' Abrir o banco de dados e executar a consulta
Set db = CurrentDb
Set rs = db.OpenRecordset(sql)
' Verificar se há resultados
If Not rs.EOF Then
' Atualizar as caixas de texto
Me!dtinicial = rs!DataInicial
Me!dtFinal = rs!DataFinal
Else
' Caso não haja resultados, limpar as caixas de texto
Me!dtinicial = Null
Me!dtFinal = Null
End If
' Fechar o recordset
rs.Close
Set rs = Nothing
Set db = Nothing
End Sub
|
|