Hi,
I am trying to export an access query to excel. I have made use of transferspreadsheet 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: - Private Sub Report_Click()
-
On Error GoTo Err_Report_Click
-
-
Dim db As DAO.Database
-
Dim qdf As DAO.QueryDef
-
Dim strSQL As String
-
Set db = CurrentDb
-
Set qdf = db.QueryDefs("CWW Billing Query")
-
-
If Me.All_cbox = True Then
-
strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
-
"FROM [CWW_Data],[CWW_Acct] " & _
-
"WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
-
"AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
-
"ORDER BY [CWW_Acct].GCWW_Acct;"
-
ElseIf Me.Loc_cbox = True Then
-
strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
-
"FROM [CWW_Data],[CWW_Acct] " & _
-
"WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
-
"AND [CWW_Acct].UC_Location = '" & Me.Loc_combo.Value & "'" & _
-
"AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
-
"ORDER BY [CWW_Acct].GCWW_Acct;"
-
ElseIf Me.SAP_cbox = True Then
-
strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
-
"FROM [CWW_Data],[CWW_Acct] " & _
-
"WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
-
"AND [CWW_Acct].SAP_Account = '" & Me.SAP_Combo.Value & "'" & _
-
"AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
-
"ORDER BY [CWW_Acct].GCWW_Acct;"
-
ElseIf Me.Acct_cbox = True Then
-
strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
-
"FROM [CWW_Data],[CWW_Acct] " & _
-
"WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
-
"AND [CWW_Acct].GCWW_Acct = '" & Me.Acct_combo.Value & "'" & _
-
"AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
-
"ORDER BY [CWW_Acct].GCWW_Acct;"
-
ElseIf Me.Premises_cbox = True Then
-
strSQL = "SELECT [CWW_Data].*,[CWW_Acct].Premises,[CWW_Acct].UC_Location,[CWW_Acct].SAP_Account,[CWW_Acct].Notes " & _
-
"FROM [CWW_Data],[CWW_Acct] " & _
-
"WHERE [CWW_Data].Billing_Month BETWEEN # " & Me.Bill_Start & " # AND # " & Me.Bill_End & " #" & _
-
"AND [CWW_Acct].Premises = '" & Me.Premises_combo.Value & "'" & _
-
"AND [CWW_Data].GCWW_Acct = [CWW_Acct].GCWW_Acct " & _
-
"ORDER BY [CWW_Acct].GCWW_Acct;"
-
-
End If
-
-
Debug.Print strSQL
-
qdf.SQL = strSQL
-
-
DoCmd.TransferSpreadsheet acExport, 8, "CWW Billing Query", "c:\test\test.xls", True, "Report"
-
-
DoCmd.Close acForm, Me.Name
-
-
Exit Sub
-
-
Err_Report_Click:
-
MsgBox "No records found for the selected query.", vbExclamation, "Information"
-
End Sub
Thanks
Kaushik
2 2064
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\2007\
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\Acct\AP\Billing\2007\"
Make sure to use UNC - not all users may have identical drive mappings.
MyFile = "Billing_ & Format([BillDate],"mm_yyyy") & ".xls"
TransferSpreadsheet .... MyPath & MyFile
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\2007\
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\Acct\AP\Billing\2007\"
Make sure to use UNC - not all users may have identical drive mappings.
MyFile = "Billing_ & Format([BillDate],"mm_yyyy") & ".xls"
TransferSpreadsheet .... 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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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"...
|
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
|
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 >...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
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...
| |