473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to export queries results into a single excel sheet as tables

Expand|Select|Wrap|Line Numbers
  1. Public Sub gets(pCity As String, pWeek As Byte)
  2.     'export function
  3.     'Exports tables in access database to Excel
  4.     'Referenec to DAO is required
  5.     Dim strExcelFile As String
  6.     Dim strWorksheet As String
  7.     Dim strDB As String
  8.     Dim strTable As String
  9.     Dim strTable1 As String
  10.     Dim strTable2 As String
  11.     Dim strTable3 As String
  12.     Dim strTable4 As String
  13.     Dim strTable5 As String
  14.     Dim strTable6 As String
  15.     Dim objDB As Database
  16.     Dim outputFileName As String
  17.  
  18.     'Change Based on your needs or use parameters as sub
  19.     strExcelFile = "C:\Documents and Settings\velal\My Documents\Book1.xls"
  20.     strWorksheet = "Council"
  21.     strDB = "C:\Documents and Settings\My Documents\Completed.mdb"
  22.     strTable = "stud"
  23.     strTable1 = "attendance"
  24.     strTable2 = "marks"
  25.     strTable3 = "fee"
  26.     strTable4 = "course"
  27.     strTable5 = "subject"
  28.     strTable6 = "PD"
  29.     Set objDB = OpenDatabase(strDB)
  30.     'If excel file already exist you can delete it here
  31.     If Dir(strExcelFile) <> "" Then Kill strExcelFile
  32.     objDB.Execute ("SELECT * INTO [Excel 8.0; DATABASE=" & _
  33.         strExcelFile & "].[" & strWorksheet & "] FROM " & "[" & strTable & "]" & _
  34.         "WHERE city = '" & pCity & "' AND [Week Periodtext] = " & pWeek)
  35.         outputFileName = "C:\Documents and Settings\velal\My Documents\Book1.xls"
  36. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "stud", outputFileName, True
  37. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "attendance", outputFileName, True
  38. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "marks", outputFileName, True
  39. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "fee", outputFileName, True
  40. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "course", outputFileName, True
  41. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "subject", outputFileName, True
  42. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "PD", outputFileName, True
  43.     objDB.Close
  44.     Set objDB = Nothing
  45. End Sub
  46. ' Start here with parameters provided
  47. Public Sub start()
  48.     Call gets("Brisbane", 5)
  49. End Sub
  50.  
Oct 13 '10 #1
2 1420
MMcCarthy
14,534 Expert Mod 8TB
Vanessa

You haven't actually asked a question, just posted a load of code. Where exactly are you having a problem? What part of your code does not work?

Mary
Oct 13 '10 #2
hi mary,
With th ecode i'm having i can import all the seven tables into seven spreadsheets of the same workbook. But now i want to make all the seven spreadsheets into one spreadsheet with all the tables in 2 columns and 3 rows. Is that possible
Oct 13 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
3
by: Eddy | last post by:
I would like to export the output of 2 queries to excel namely: 1. QryProrationbyWBS_1 2. QryProrationbyWBS_2 However I want to do this using the same spreadsheet say sheet1 and sheet2 or...
3
by: Sachin Salgarkar | last post by:
I have a DataSet that I need to export to Excel. The dataset has multiple tables. I need a way to export the complete dataset to a single Excel Workbook with sheets for each table in the dataset....
2
by: VitorCastro | last post by:
Hello... First, sorry for my bad english... i have generated many pivot tables in Access 2003. and i want the code to export all of them to one single excel sheet and specific cell. i have...
4
by: Chris Gilpin | last post by:
Hey everybody. I have Access set up using VBA to run a bunch of queries automatically, and then export the results into Excel. The only problem is, I want each query to be exported to the same...
6
by: gmujjain4902 | last post by:
Hi, Please help me with code for to Export HTML table to Excel sheet using javascript without using ActiveX controls... The problem is i could get solution for my problem via ActiveX control...
3
by: hotflash | last post by:
Hi All, Instead of displaying the search results such as names, phones, etc... on the screen, is there a way to export this information into an EXCEL format using ASP? Please advise. Thanks...
11
by: Blacky | last post by:
hi, I have a dataTable in Session.On the click of a button in a Modal Dialog window I need to export this dataTable to Excel sheet.How could i do this...?? i tried using a...
2
by: RajeshPune | last post by:
We are deveopingawebiste in asp.net. There are tempelates of each aspx page made in the form of excel sheet. Upon completion of the online calculation, the user is to be allowed to export the results...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.