Access query via VBA

Asked

Viewed 447 times

2

I have an Access base and I have problems with the QUERY result.

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

Below the QUERY I am 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 search fields with specific conditions. Do I need to enable some tool in the references of vba? Or is there another way to solve this problem? Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.