Avatar billede xenoxsis Nybegynder
27. februar 2008 - 09:39 Der er 8 kommentarer og
1 løsning

Adding query results to Excel

Hi

I found out that I needed to add some results from a Query to an Excel spreadsheet. The Pivot Query gives the following result:

  January February May  June July September October November
T Data  Data      Data Data Data Data      Data    Data
B Data  Data      Data HERE Data Data      Data    Data
F Data  Data      Data Data Data Data      Data    Data

Now I need to take for instance the value for B, June - and get it out so I can add it to a specific Excel cell, and then I need to take T,February and add that to a different Excel Cell. I use this to add to the Excel sheet:

Dim objXL    As Excel.Application
Dim strMyData As String
strMyData = <This is where I need the value>
Set objXL = New Excel.Application
objXL.Visible = True
objXL.Workbooks.Add
  objXL.Cells(1, 1).Formula = strMyData

But again I don't know how to pull the specific data from the query.
Avatar billede fdata Forsker
27. februar 2008 - 12:35 #1
Have you tried: DLookup("June"; "QueryName"; "FirstColumnName='B'")
(please replace QueryName and FirstColumnName with your own values)
Avatar billede xenoxsis Nybegynder
27. februar 2008 - 13:51 #2
My Query is a crosstab looking like this (this is more like how mine looks, the above one was more an example):

          January February etc.
Banks
Company
Insurance

I tried:

DLookup("June", "[F-REPORT - General - Amount]", "Name='Banks'")

It says that it doesn't recognize the field: Name.

But in the Query that is exactly what its called.
Avatar billede fdata Forsker
27. februar 2008 - 16:19 #3
As 'Name' is a reserved Word i Access you should avoid using this as a field name. Try renaming the field in the query.
(in a report 'Name' would return the name of the report instead the field 'Name' - maybe this is the case in a Pivot Query as well)
Avatar billede terry Ekspert
27. februar 2008 - 18:10 #4
great to see everyone writing english :o)
Avatar billede terry Ekspert
27. februar 2008 - 18:10 #5
If we keep it up then maybe eksperten can become an international IT forum
Avatar billede fdata Forsker
27. februar 2008 - 20:51 #6
Keep dreaming  ;o]
Avatar billede terry Ekspert
28. februar 2008 - 19:16 #7
:o)
Avatar billede xenoxsis Nybegynder
13. marts 2008 - 13:21 #8
Well the assignment got cancelled, so I dont need to fix that one anymore. You'll get credit none the less...
Avatar billede fdata Forsker
14. marts 2008 - 19:43 #9
Nice move. Thanx  ;o)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester