AJUDA COM SQL E DATA REPORT
GALERA ME DEPAREI UM COM UM PROBLEMINHA AQUI TENHO UM DATAREPORT QUE ME MOSTRA OS ITENS DE UMA VENDA MAIS AGORA INCLUIR UM SEGUNDO BANCO COM OUTRAS VENDAS COMO ADAPTAR ESSA CONSULTA SQL PRA PESQUISAR EM DOIS BANCOS DE DADOS E MOSTRAR EM APENAS UM DATAREPORT
ESSA E A CONSULTA QUE UTILIZA PARA UM BANCO
COMO ADICIONAR PARA DOIS BANCOS DE DADOS
Dim db_file As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim A1 As String
Dim Data1 As Date
Dim Data2 As Date
Data1 = DTPicker1
Data2 = DTPicker2
[ô]RSProdutos.Open
[ô]a1 = [Ô]SELECT * FROM CLIENTES[Ô]
[ô]A1 = [Ô]SELECT * From caixa where (((venc2) Like [ô][Ô] & [Ô]A PAGAR[Ô] & [Ô][ô])) AND venc1 BetWeen #[Ô] & (Data1) & [Ô]# And #[Ô] & (Data2) & [Ô]# ;[Ô]
A1 = [Ô]SELECT * From osentra where (((VENDEDOR) Like [ô][Ô] & Text8.Text & [Ô][ô]) and STATUSOS=[ô][Ô] & [Ô]FECHADA[Ô] & [Ô][ô]) AND DATAENTR BetWeen #[Ô] & Format$(Data1, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
[ô]a1 = [Ô]SELECT * From caixa where venc3 BetWeen #[Ô] & Format$(Data1, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
On Error GoTo ERRO
If MsgBox([Ô]Confirma a impressão do relatório?[Ô], vbQuestion + vbYesNo + vbDefaultButton2, [Ô]TeclaOS[Ô]) = vbNo Then Exit Sub
[ô] Get the data.
db_file = App.Path
If Right$(db_file, 1) <> [Ô]\[Ô] Then db_file = db_file & [Ô]\[Ô]
db_file = db_file & [Ô]\dados\dados.mdb[Ô]
[ô] Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
[Ô]Provider=Microsoft.Jet.OLEDB.4.0;[Ô] & _
[Ô]Data Source=[Ô] & db_file & [Ô];[Ô] & _
[Ô]Persist Security Info=False[Ô]
conn.Open
[ô] Open the Recordset.
[ô]Set rs = conn.Execute([Ô]SELECT * FROM osentra[Ô], , adCmdText)
Set rs = conn.Execute(A1, , adCmdText)
[ô] Connect the Recordset to the DataReport.
Set vend.DataSource = rs
vend.WindowState = vbMaximized
vend.Sections([Ô]Section5[Ô]).Controls([Ô]label10[Ô]).Caption = Text13.Text
vend.show vbModal
rs.Close
conn.Close
Unload Me
Exit Sub
ERRO:
ESSA E A CONSULTA QUE UTILIZA PARA UM BANCO
COMO ADICIONAR PARA DOIS BANCOS DE DADOS
Dim db_file As String
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim A1 As String
Dim Data1 As Date
Dim Data2 As Date
Data1 = DTPicker1
Data2 = DTPicker2
[ô]RSProdutos.Open
[ô]a1 = [Ô]SELECT * FROM CLIENTES[Ô]
[ô]A1 = [Ô]SELECT * From caixa where (((venc2) Like [ô][Ô] & [Ô]A PAGAR[Ô] & [Ô][ô])) AND venc1 BetWeen #[Ô] & (Data1) & [Ô]# And #[Ô] & (Data2) & [Ô]# ;[Ô]
A1 = [Ô]SELECT * From osentra where (((VENDEDOR) Like [ô][Ô] & Text8.Text & [Ô][ô]) and STATUSOS=[ô][Ô] & [Ô]FECHADA[Ô] & [Ô][ô]) AND DATAENTR BetWeen #[Ô] & Format$(Data1, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
[ô]a1 = [Ô]SELECT * From caixa where venc3 BetWeen #[Ô] & Format$(Data1, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
On Error GoTo ERRO
If MsgBox([Ô]Confirma a impressão do relatório?[Ô], vbQuestion + vbYesNo + vbDefaultButton2, [Ô]TeclaOS[Ô]) = vbNo Then Exit Sub
[ô] Get the data.
db_file = App.Path
If Right$(db_file, 1) <> [Ô]\[Ô] Then db_file = db_file & [Ô]\[Ô]
db_file = db_file & [Ô]\dados\dados.mdb[Ô]
[ô] Open a connection.
Set conn = New ADODB.Connection
conn.ConnectionString = _
[Ô]Provider=Microsoft.Jet.OLEDB.4.0;[Ô] & _
[Ô]Data Source=[Ô] & db_file & [Ô];[Ô] & _
[Ô]Persist Security Info=False[Ô]
conn.Open
[ô] Open the Recordset.
[ô]Set rs = conn.Execute([Ô]SELECT * FROM osentra[Ô], , adCmdText)
Set rs = conn.Execute(A1, , adCmdText)
[ô] Connect the Recordset to the DataReport.
Set vend.DataSource = rs
vend.WindowState = vbMaximized
vend.Sections([Ô]Section5[Ô]).Controls([Ô]label10[Ô]).Caption = Text13.Text
vend.show vbModal
rs.Close
conn.Close
Unload Me
Exit Sub
ERRO:
RESOLVI ASSIM
Dim Data3 As Date
Dim Data2 As Date
Data3 = DTPicker1
Data2 = DTPicker2
[Ô]SELECT OSENTRA.CLIENTNOME,OSENTRA.OSN,OSENTRA.NODEPR,OSENTRA.PSAIDA,OSENTRA.VENDEDOR,OSENTRA.DATAENTR,OSENTRA.DATASAID,OSENTRA.STATUSOS,OSENTRA.VALORPONT,OSENTRA.vlr,OSENTRA.VALORTOTA, ITENS.CODIG,ITENS.client,ITENS.DESCRICAO,ITENS.CATEGORIA,ITENS.VALORUNIT,ITENS.QUANTI,ITENS.DATE,ITENS.VALOR From OSENTRA, ITENS Where OSENTRA.CLIENTNOME = ITENS.client AND DATAENTR BetWeen #[Ô] & Format$(Data3, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
Dim Data3 As Date
Dim Data2 As Date
Data3 = DTPicker1
Data2 = DTPicker2
[Ô]SELECT OSENTRA.CLIENTNOME,OSENTRA.OSN,OSENTRA.NODEPR,OSENTRA.PSAIDA,OSENTRA.VENDEDOR,OSENTRA.DATAENTR,OSENTRA.DATASAID,OSENTRA.STATUSOS,OSENTRA.VALORPONT,OSENTRA.vlr,OSENTRA.VALORTOTA, ITENS.CODIG,ITENS.client,ITENS.DESCRICAO,ITENS.CATEGORIA,ITENS.VALORUNIT,ITENS.QUANTI,ITENS.DATE,ITENS.VALOR From OSENTRA, ITENS Where OSENTRA.CLIENTNOME = ITENS.client AND DATAENTR BetWeen #[Ô] & Format$(Data3, [Ô]mm/dd/yyyy[Ô]) & [Ô]# And #[Ô] & Format$(Data2, [Ô]mm/dd/yyyy[Ô]) & [Ô]# ;[Ô]
Tópico encerrado , respostas não são mais permitidas