473,770 Members | 6,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exporting Access query to Excel

2 New Member
Hi,

I am trying to export an access query to excel. I have made use of transferspreads heet command to achive this. However i have hardcoded the path and the filename in the VBA code. I am not sure as to how i can make the user enter his ownfile name and select the location where the file is to be written.

I am attaching below my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_Click()
  2. On Error GoTo Err_Report_Click
  3.  
  4. Dim db As DAO.Database
  5. Dim qdf As DAO.QueryDef
  6. Dim strSQL As String
  7. Set db = CurrentDb
  8. Set qdf = db.QueryDefs("CWW Billing Query")
  9.  
  10. If Me.All_cbox = True Then
  11.     strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
  12.              "FROM [CWW_Data],[CWW_Acct] " & _
  13.              "WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
  14.              "AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
  15.              "ORDER BY [CWW_Acct].GCWW_Acct;"
  16. ElseIf Me.Loc_cbox = True Then
  17.     strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
  18.              "FROM [CWW_Data],[CWW_Acct] " & _
  19.              "WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
  20.              "AND [CWW_Acct].UC_Location = '" & Me.Loc_combo.Value & "'" & _
  21.              "AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
  22.              "ORDER BY [CWW_Acct].GCWW_Acct;"
  23. ElseIf Me.SAP_cbox = True Then
  24.     strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
  25.              "FROM [CWW_Data],[CWW_Acct] " & _
  26.              "WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
  27.              "AND [CWW_Acct].SAP_Account = '" & Me.SAP_Combo.Value & "'" & _
  28.              "AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
  29.              "ORDER BY [CWW_Acct].GCWW_Acct;"
  30. ElseIf Me.Acct_cbox = True Then
  31.     strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
  32.              "FROM [CWW_Data],[CWW_Acct] " & _
  33.              "WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
  34.              "AND [CWW_Acct].GCWW_Acct = '" & Me.Acct_combo.Value & "'" & _
  35.              "AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
  36.              "ORDER BY [CWW_Acct].GCWW_Acct;"
  37. ElseIf Me.Premises_cbox = True Then
  38.     strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
  39.              "FROM [CWW_Data],[CWW_Acct] " & _
  40.              "WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
  41.              "AND [CWW_Acct].Premises = '" & Me.Premises_combo.Value & "'" & _
  42.              "AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
  43.              "ORDER BY [CWW_Acct].GCWW_Acct;"
  44.  
  45. End If
  46.  
  47. Debug.Print strSQL
  48. qdf.SQL = strSQL
  49.  
  50. DoCmd.TransferSpreadsheet acExport, 8, "CWW Billing Query", "c:\test\test.xls", True, "Report"
  51.  
  52. DoCmd.Close acForm, Me.Name
  53.  
  54. Exit Sub
  55.  
  56. Err_Report_Click:
  57.     MsgBox "No records found for the selected query.", vbExclamation, "Information"
  58. End Sub
Thanks
Kaushik
Jan 8 '08 #1
2 2080
jaxjagfan
254 Recognized Expert Contributor
I did a similar process several years ago (SAP environment as well). We created a billing folder on the network and pushed the files created to the network folder. We also dynamically named the files based on the Billing Month being processed.

Our network path was similar to:

\\MyServer\Acct \AP\Billing\200 7\

Each file was named

Billing_01_2007 .xls
Billing_02_2007 .xls

(They had wanted the months (Jan, Feb) initially but then realized the numerics allowed for better sorting) If not now they will complain about this later.

Be consistent with locations and naming structures. Never know what an employee will name a file or where they will put it.

MyPath ="\\MyServer\Ac ct\AP\Billing\2 007\"
Make sure to use UNC - not all users may have identical drive mappings.
MyFile = "Billing_ & Format([BillDate],"mm_yyyy") & ".xls"

TransferSpreads heet .... MyPath & MyFile
Jan 8 '08 #2
Comandur
2 New Member
I did a similar process several years ago (SAP environment as well). We created a billing folder on the network and pushed the files created to the network folder. We also dynamically named the files based on the Billing Month being processed.

Our network path was similar to:

\\MyServer\Acct \AP\Billing\200 7\

Each file was named

Billing_01_2007 .xls
Billing_02_2007 .xls

(They had wanted the months (Jan, Feb) initially but then realized the numerics allowed for better sorting) If not now they will complain about this later.

Be consistent with locations and naming structures. Never know what an employee will name a file or where they will put it.

MyPath ="\\MyServer\Ac ct\AP\Billing\2 007\"
Make sure to use UNC - not all users may have identical drive mappings.
MyFile = "Billing_ & Format([BillDate],"mm_yyyy") & ".xls"

TransferSpreads heet .... MyPath & MyFile
Thank you for the suggestion. However these reports will not be generated every billing month, rather they will be generated by the various at their need. What i would like to do is to pop up a save as dialog box and allow the user to select the location and enter the file name. It there a way to do this?

Thanks
Kaushik
Jan 9 '08 #3

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

Similar topics

3
9248
by: sridevi | last post by:
Hello How to export data from ms-access database to excel worksheet using ASP. mainly i need to export data to multiple worksheets. it is very urgent to us. i have a sample code which works only exporting to single worksheet. but i need to export data to multiple worksheets. it is very urgent to us. so please help me in code.
4
3949
by: D | last post by:
I've created a report with many subreports of aggregate data. I want my client to be able to export this data to Excel to make her charts, etc. Only one problem: one of the fields is a "SchoolYear" TEXT field that contains data such as 2000/01, 2001/02, etc. If I export a Query with this kind of data to Excel, it gives me the text value of this field; however, when I export a Report bound to this TEXT field, Excel gives me the values 36526,...
2
8013
by: Kenneth | last post by:
How do I remove the limitation in Access that deny me from exporting 24000 rows and 17 columns (in a query) into Excel? Kenneth
1
7798
by: Suffrinmick | last post by:
Hello Everyone I've built a database using Access 2000 which includes a query which is built using a form containing filters. No problem. When I export the results of the query to excel, (File > Export > Save as type: Microsft Excel 97-2000) one of the fields, which is a memo field type, loses any data over the first 255 characters. How do I get all the data into excel? Thanks
21
6247
by: bobh | last post by:
Hi All, In Access97 I have a table that's greater than 65k records and I'm looking for a VBA way to export the records to Excel. Anyone have vba code to export from access to excel and have the code use multiple excel tabs within a workbook???? Anyone have vba code that would create a temp table write 65,000 records to it, export those to excel, clean the temp table, append the next 65,000 records, export it to excel with a different...
16
10076
by: robertmeyer1 | last post by:
Hey, I am working on creating a query which will export the information to excel. I have a specific excel document which has line by line items (corresponds to access query). Here's the layout of the excel doc. Each row is a different line item. Each column is a different entity. So there are about 750 entities which will be exported to this excel doc. (1 entity per column). For access, I have the same information as the excel...
6
2186
by: jpatchak | last post by:
Hi, I have kind of a strange problem. I have a report that I need to export to excel. The report opens fine in Access and when I export it or click on "Analyze It with Microsoft Office Excel," I get the dialog that says it's exporting page n of total to file such and such. I get no error message. However, no Excel file is created. I've tracked down the problem to one of my fields on the report. It is a field called "ExpectedRate," with...
2
2054
by: eskelies | last post by:
Hello all, I have data, which is separated into account numbers (ie. 10, 20, 30), but it exists in one query. Right now, I have an access macro "transferspreadsheet," which is exporting all the account numbers into one worksheet. My question: How can I go about exporting data from the query into excel, so that each different fund number has it's own worksheet and it's corresponding data? Thank you. Your assistance would be greatly...
4
2396
by: myemail.an | last post by:
Hi all, I use Access 2007 and have the following problems: when exporting banal select queries (either to Excel or to a csv file) I find that exporting often doesn't work and creates a file with the WHOLE dataset, i.e. including those rows which the criteria of the query excluded. For example: let's say I have a database with sales by region. I create a select query to only show sales from Europe. The query runs
9
2780
by: QCLee | last post by:
Sir can you help me to transfer my Access Query to MS excel? i have a command button on the form to export the parameter query named "HVACWindwardQuery" to excel spreadsheet and i got the codes from searching on the internet and books but the problem is when i run the command button "Export" it just only open the Blank Spreadsheet, no data at all that it came from my query named "HVACWindwardQuery" and there's an error on it...
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.