Access Query via VBA

2

I have an Access database and I'm having problems with QUERY's results.

When I run this same QUERY in access, it runs normally, but when I play in VBA it does not give an error, but it does not return any record in RECORSET.

Below is the QUERY I'm using:

Set BD = New ADODB.Connection     
BD.Open ConectaBD        
sWHERE = "WHERE (((BASE_PREMIO.UF)=""SP"") AND ((BASE_PREMIO.cliente)=""CAASP"") AND ((BASE_PREMIO.GrupoPlano)=""ESPECIAL"") AND ((BASE_PREMIO.Região)=""SUDESTE"") AND ((BASE_PREMIO.TpEntidade)=""FECHADA"") AND ((BASE_PREMIO.Corretor) Like ""*""))"        
QUERY = "SELECT BASE_PREMIO.REFERENCIA, Sum(BASE_PREMIO.Premio_Sum) AS SomaDePremio_Sum, Sum(BASE_PREMIO.Vidas_Sum) AS SomaDeVidas_Sum, Sum(IIf([DIF_MES_VENDAS_MATURADAS]>2,[PREMIO_SUM],0)) AS [VENDA MATURADA_PREMIO], Sum(IIf([DIF_MES_VENDAS_MATURADAS]>2,[VIDAS_SUM],0)) AS [VENDA MATURADA_VIDAS], Sum(IIf([VENDAS]=""S"",[PREMIO_SUM],0)) AS VENDA_PREMIO, Sum(IIf([VENDAS]=""S"",[VIDAS_SUM],0)) AS VENDA_VIDAS, Sum(IIf([VENDAS]=""N"",[PREMIO_SUM],0)) AS ESTOQUE_PREMIO, Sum(IIf([VENDAS]=""N"",[VIDAS_SUM],0)) AS ESTOQUE_VIDAS "        
QUERY = QUERY & "FROM BASE_PREMIO "        
QUERY = QUERY & sWHERE        
QUERY = QUERY & " GROUP BY BASE_PREMIO.REFERENCIA;"        
Set RS = New ADODB.Recordset            
RS.Open QUERY, BD

I think the problem occurs because I'm looking for fields with specific conditions. Do I need to enable some tool in the vba references? Or is there another way to solve this problem? Thank you.

    
asked by anonymous 30.10.2017 / 20:55

0 answers