473,404 Members | 2,137 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,404 software developers and data experts.

Export Query to .xlsx file and set name based on Combo-box value

Hi,

Consider you would have to extract daily reports showing orders received by department (consider 5 departments) and you would need to export them to files named after each department (Dep1.xlsx, Dep2.xlsx, and so on).

How I solved this was to have a query for each department and also create an export button for each query (date is taken from a text box). This way each button runs the query for a particular department and then exports it to Dept_name.xlsx

So 6 queries & 6 buttons....this solution is very basic to say the least.

A nicer solution would be to have a single query and set the parameters via a text box (for the date) and a combo-box (for the department name).
This I have done, also quite easy.

The question would be, can you then export the resulting query (say you select Dep.1 in the combo-box) to an Excel file and have it's name determined from the department selected (Report "Dep1".xlsx)?
This would help a lot since I can have a single query, a single button, and in case department lists change, I's just have to add it and not go through the whole process of creating deleting a query and a button.....

Thanks a lot
Aug 18 '14 #1
6 1785
twinnyfo
3,653 Expert Mod 2GB
alecs0101,

Yes, this is very simple to do. For the name of the file, just use the column in your combo box that corresponds to the department. For exampl,e if you combo box row source lists the dept ID and the dept Name, Me.cboDept.Column(0) = the ID and Me.cboDept.Column(1) = the Department name.

Incorporate that value into the file name and you should be good to go. Sounds like you have a pretty good grasp of many of the details, but if you need help, we are standing by.
Aug 18 '14 #2
:) I have a logical grasp but am barely a beginner with access...functions and VBA ....brrr.... works only after first documenting and seeing examples from others ... and then not always

Now comes the "dumb/noobish" question, how/where can I incorporate --- Me."combo_box_name".Column(1)the file name --- in the file name? :)

I presume that in order for you to answer, you would first need some extra details....if so please let me know what and I'll spit it all out :)

Thanks
Aug 18 '14 #3
twinnyfo
3,653 Expert Mod 2GB
So, the first question is to ask how you were exporting the queries previously? Did you have a form that exported them? Were you doing this manually?

I need to know how far along you are in the porcess before guiding further.

Don't worry about being a noob, as I was a noob at one time, too. Just keep at it, and you will get the hang of things.
Aug 18 '14 #4
Considering there are 4 departments...current solution is:
- there is one query that returns the date for each department in turn (total 4 queries)
- on the form there is a text box where one selects the date/interval for which they want to view the data (included in the criteria of all 4 queries)
- there are four buttons (one for each department) linked to the respective query and the text box
- buttons are set to export the query results to an excel file
- as each button connected to a different query, it was set up to save it directly (no prompts) based on the query...

The concern is that:
1. it is rather a stone age solution...or basic at least
2. if departments say add up, having +4 queries and +4 buttons seems really stupid :)

So the idea is to merge all queries into 1, I know how to do that - discovered rather (by adding a combo box with all departments).
Problem is that now, upon exporting I have to manually write the name of the file - basically "Report + dep. name".

Would like if possible for the report to be saved and name to include the dep. selected in the combo box
Aug 18 '14 #5
twinnyfo
3,653 Expert Mod 2GB
Again, see my post #2.

If your code is building the string for the report name, just use hte combo box instead of whatever method you had for typing it in yourself (I don't know how you are doing this, as you don't mention).

Example:

Expand|Select|Wrap|Line Numbers
  1. strFileName = "My Report - " & _
  2.     Me.cboDept.Column(1) & _
  3.     " - " & strDate & ".xlsx"
This assumees that you have created a string for the date format you desire.

What you are trying to do seems to be rather straightforward and I use this methodology all the time. I think once you understand the concepts, you will be able to use them in all aspects of your projects.
Aug 18 '14 #6
NeoPa
32,556 Expert Mod 16PB
It would help us to see the code you are using currently Alecs.

You describe quite well (which is really great) but on this occasion we need to see your existing code to know where to start explaining from.
Aug 18 '14 #7

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

Similar topics

3
by: CJA | last post by:
Hi I have a script that will compact an Access MDB and a copy to a new folder. I would it to give each export a unique file name. I can do this with an absolute file reference but I am...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
4
by: kevin | last post by:
Hi, I am trying to create a page so the user can browse the network, select a file and have that file name (text) inserted into our sql DB so I can build the hyperlink path later on. Here's what...
6
by: Inge Jones | last post by:
I have a form that dynamically generates Submit buttons. I want all the buttons to display the same text "More info" while their names are dynamically generated numeric names (they point to database...
2
by: Marisol2 | last post by:
I have some queries in Access 2003 db that I have setup to display as pivots. I can go into design pivot table view and click on and then click on Export to Office MicroSoft Excel. The problem is I...
0
by: Ivan Stefanov | last post by:
Hello, I have the following problem: I created a website project and I want in that website to be make a button, which will export some data in an excel file. This is the code that I have: using...
0
by: Kumaraguru | last post by:
Hi I have load the xlsx file in blob using POI when i tried to download the xlsx file from blob the xlsx file got saved but its not openening. when i tried to open the file its giving following...
7
by: surfside1 | last post by:
Hi, I have a Pivot table query in access 2007 and I want to export it to excel and provide a directory location and file name. I've tried all of these statements below and the only ones that work...
2
by: MarkLafferty | last post by:
I am running MS SQL Server 2008. I frequently need to manually run a large quantity of query files at a time. I need to log the results of the queries to a file without having to enter a new file...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.