PC Review


Reply
Thread Tools Rate Thread

Database in Excel

 
 
gatarossi@ig.com.br
Guest
Posts: n/a
 
      18th Sep 2007
Dear all,

The code below brings the information form access database... I want
now that it bring the data from an excel sheet...

How can I transform this code for it?

Sub retorna_valores_grafico_det()

Dim adoconn As ADODB.Connection
Dim adors As ADODB.Recordset
Dim sql As String
Dim filenm As String
Dim xlsht As Excel.Worksheet
Dim lin As Long
Dim col As Long
Dim x As Variant

Set xlsht = Sheets("gráfico")
Set x = Cells(4, 2)

filenm = ThisWorkbook.Path & "\dados.mdb"

contador = 3

Do Until contador = 9

Select Case x

Case "OR"
sql = "SELECT Sum(informacoes_receita.orders_received) AS
SomaDeorders_received "
sql = sql & "FROM segmento INNER JOIN (periodo INNER JOIN
(centro_negocio INNER JOIN informacoes_receita ON
centro_negocio.codigo_centro = informacoes_receita.codigo_centro) ON
periodo.ano_mes = informacoes_receita.ano_mes) ON
segmento.codigo_segmento = centro_negocio.codigo_segmento "
sql = sql & "GROUP BY periodo.ano_trimestre, segmento.codigo_segmento,
informacoes_receita.tipo, informacoes_receita.real_forec "
sql = sql & "HAVING (((periodo.ano_trimestre)='" & Cells(3, contador)
& "') "
sql = sql & "AND ((segmento.codigo_segmento)='" & Cells(2, 2) & "') "
sql = sql & "AND ((informacoes_receita.tipo)='" & Cells(5, 2) & "') "
sql = sql & "AND ((informacoes_receita.real_forec)='" & Cells(2,
contador) & "')) ;"
Call getCn(adoconn, adors, sql, filenm, "", "")
xlsht.Cells(4, contador).CopyFromRecordset adors

Case "NI"
sql = "SELECT Sum(informacoes_receita.net_invoice) AS
SomaDeorders_received "
sql = sql & "FROM segmento INNER JOIN (periodo INNER JOIN
(centro_negocio INNER JOIN informacoes_receita ON
centro_negocio.codigo_centro = informacoes_receita.codigo_centro) ON
periodo.ano_mes = informacoes_receita.ano_mes) ON
segmento.codigo_segmento = centro_negocio.codigo_segmento "
sql = sql & "GROUP BY periodo.ano_trimestre, segmento.codigo_segmento,
informacoes_receita.tipo, informacoes_receita.real_forec "
sql = sql & "HAVING (((periodo.ano_trimestre)='" & Cells(3, contador)
& "') "
sql = sql & "AND ((segmento.codigo_segmento)='" & Cells(2, 2) & "') "
sql = sql & "AND ((informacoes_receita.tipo)='" & Cells(5, 2) & "') "
sql = sql & "AND ((informacoes_receita.real_forec)='" & Cells(2,
contador) & "')) ;"
Call getCn(adoconn, adors, sql, filenm, "", "")
xlsht.Cells(4, contador).CopyFromRecordset adors

Case "GM"
sql = "SELECT Sum(informacoes_receita.gross_margin) AS
SomaDeorders_received "
sql = sql & "FROM segmento INNER JOIN (periodo INNER JOIN
(centro_negocio INNER JOIN informacoes_receita ON
centro_negocio.codigo_centro = informacoes_receita.codigo_centro) ON
periodo.ano_mes = informacoes_receita.ano_mes) ON
segmento.codigo_segmento = centro_negocio.codigo_segmento "
sql = sql & "GROUP BY periodo.ano_trimestre, segmento.codigo_segmento,
informacoes_receita.tipo, informacoes_receita.real_forec "
sql = sql & "HAVING (((periodo.ano_trimestre)='" & Cells(3, contador)
& "') "
sql = sql & "AND ((segmento.codigo_segmento)='" & Cells(2, 2) & "') "
sql = sql & "AND ((informacoes_receita.tipo)='" & Cells(5, 2) & "') "
sql = sql & "AND ((informacoes_receita.real_forec)='" & Cells(2,
contador) & "')) ;"
Call getCn(adoconn, adors, sql, filenm, "", "")
xlsht.Cells(4, contador).CopyFromRecordset adors


End Select

contador = contador + 1

Loop

adors.Close
adoconn.Close

Set adors = Nothing
Set adoconn = Nothing
Set xlsht = Nothing

End Sub

Thanks in advance!

André.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update Excel Database via Access Main Database with a script Finnbar Microsoft Excel New Users 2 3rd Nov 2008 07:24 PM
HELP: Need macro for excel to get data from server database and use results to populate an Access Database Clinton M James Microsoft Access 1 7th Oct 2007 04:32 PM
Using Excel as a database and need macro or vba to take data entered on one tab and update the database by adding to the next avail row rjr Microsoft Excel Programming 5 11th Jun 2006 09:43 PM
Excel query of Access database - changed database filename, now error ucdcrush@gmail.com Microsoft Excel Discussion 2 8th Mar 2006 08:42 PM
exporting an excel file from database; making changes to excel file and updating the database by importing it back Luis Esteban Valencia Microsoft ASP .NET 1 12th Jan 2005 12:28 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:38 AM.