473,382 Members | 1,745 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,382 software developers and data experts.

Is there a way to generate an Excel file directly from a MS Access form?

26
I currently have Access form that lists a series of reports that the users can run. Users click a command button to create these reports, and a.pdf is generated. I am wondering if it is possible to generate an .xlsx file instead of the .pdf? Also, I have an issue in coding the location to save the files, whether they be .pdf or .xlsx, because the users access the Access app through Citrix. This perhaps should be entered as a separate question? Thank you..
Feb 22 '12 #1
13 2100
NeoPa
32,556 Expert Mod 16PB
3C4J5D:
This perhaps should be entered as a separate question?
Absolutely.

As for generating Excel files the answer to that is it's certainly possible. With so little detail and no signs of any attempt to start this yourself though, I can only point you towards the DoCmd.TransferSpreadsheet() function at this stage. There are more options, but I don't have any question framework within which to share those.
Feb 22 '12 #2
3c4j5d
26
Currently, the code is using the DoCmd.OutputTo. I was trying to use this command, when I need to use the TransferSpreadsheet command is what you're saying.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OutputTo acOutputReport, "rpt_AuditCompletion", "PDF Format (*.pdf)", AdataLoc & "\MAAR-AuditCompletion.pdf", True, , , acExportQualityPrint
I think because I was able to change it from a .doc to a .pdf file, I thought it would be possible to somehow use the same command to create the .xlsx type file.
Feb 22 '12 #3
NeoPa
32,556 Expert Mod 16PB
3C4J5D:
when I need to use the TransferSpreadsheet command is what you're saying
Indeed. If you were using the other before, then look at this one now (as OutputTo won't help here).
Feb 22 '12 #4
3c4j5d
26
Okay, thank you very much!
Feb 22 '12 #5
3c4j5d
26
I now have the following code producing a spreadsheet, but I cannot open the resulting Excel file. Here is the code I am using:
Expand|Select|Wrap|Line Numbers
  1. Private Sub AuditCompletionDetailCountManagers_Click()
  2.  
  3.    AdataLoc = "N:\My Documents"
  4.  
  5.     Mo = Format(Now(), "mm")
  6.     Dy = Format(Now(), "dd")
  7.     Yr = Format(Now(), "yyyy")
  8.  
  9.     ExcelFilePath = AdataLoc & "\AuditCompDetailCountMgrs" & Yr & Mo & Dy & ".xlsx"
  10.  
  11.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, "qry_AuditCompletionDetailCountMgrs", ExcelFilePath, True
  12.     DoCmd.SetWarnings True
  13.  
  14. End Sub
It looks like the Excel file is created, with correct filename, extension, location. The size is 1790 MB. But when trying to open it, this message is generated: "Excel cannot open the file 'AuditCompDetailCountMgrs20120222.xlsx' because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file." Can you see any reason this may be caused? Thank you!
Feb 22 '12 #6
JayF
45
I can't help, sorry, I came to this topic for an answer myself. But did you actually mean to say it's producing a 1.7Gb xlsx? Or did you mean 1,790Kb?
Feb 22 '12 #7
3c4j5d
26
Jay,
Sorry, I did mean to say 1790Kb. Thanks!
Feb 22 '12 #8
Mihail
759 512MB
Try that (of course you must adapt to your needs):

Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateExcelWorkbook()
  2. ' Requires a Reference to Microsoft Excel 8.0 Object Library or Higher
  3. ' In VBE, goto Tools->References... and select it from the list
  4. On Error GoTo ErrorHandler
  5.     ' If Excel is open, use GetObject, otherwise create a new Excel object
  6.     Set objExcel = GetObject(, "Excel.Application")
  7.  
  8.     With objExcel
  9.         ' Adds a new workbook to the Excel environment
  10.         .Workbooks.Add
  11.         .ActiveWorkbook.SaveAs ("C:\TestareExcel.xlsx")
  12.         ' Excel VBA Code goes here
  13.  
  14.         ' Causes the Excel window to become visible
  15.         .Visible = True
  16.     End With
  17. Ex:
  18. Exit Sub
  19.  
  20. ErrorHandler:
  21.     Select Case Err.Number
  22.         Case 429 'Application not runing
  23.             Resume Next
  24.         Case Else
  25.             MsgBox (Err.Number & " " & Err.Description)
  26.             Resume Ex
  27.     End Select
  28. End Sub
This is an adaptation from a NeoPa's article (Application Automation).
Feb 23 '12 #9
3c4j5d
26
Mihail,
Thanks for your reply. That generated a file that could be opened. Thank you!
Feb 23 '12 #10
3c4j5d
26
I am still having trouble getting the Access query to generate the Excel spreadsheet and open it up. With the code below, the Excel application must be running to work; a blank workbook called ExcelFilePath is created, and it is necessary to go to the location of the saved file and open it there.
Expand|Select|Wrap|Line Numbers
  1. Private Sub AuditCompletionDetailCountManagers_Click()
  2. 'AdataLoc = Environ("APPDATA")
  3.    AdataLoc = "N:\My Documents"
  4.  
  5. On Error GoTo ErrorHandler
  6. Set objExcel = GetObject(, "Excel.Application")
  7. With objExcel
  8.     .Workbooks.Add
  9.     .ActiveWorkbook.SaveAs ("ExcelFilePath.xlsx")
  10.     '.ActiveWorkbook.SaveAs ExcelFilePath
  11.  
  12.     Mo = Format(Now(), "mm")
  13.     Dy = Format(Now(), "dd")
  14.     Yr = Format(Now(), "yyyy")
  15.  
  16. 'Export audit completion detail report counts of managers in Excel
  17.  
  18.     ExcelFilePath = AdataLoc & "\AuditCompDetailCountMgrs" & Yr & Mo & Dy & ".xlsx"
  19.  
  20.     DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "QRY_AuditCompletionSummaryDetailMgrs", ExcelFilePath, True
  21.     DoCmd.SetWarnings True
  22.     .Visible = True
  23. End With
  24. Ex:
  25. Exit Sub
  26.  
  27. ErrorHandler:
  28.     Select Case Err.Number
  29.         Case 429 'Application not running
  30.             Resume Next
  31.         Case Else
  32.             MsgBox (Err.Number & " " & Err.DESCRIPTION)
  33.             Resume Ex
  34.     End Select
  35.  
  36. End Sub
Feb 24 '12 #11
NeoPa
32,556 Expert Mod 16PB
I would suggest that the DoCmd.TransferSpreadsheet() should be run before you try to open the workbook up in Excel. This thread should be focused on getting this part to work, and not on any surrounding issues. As previously discussed, that is a topic for another thread.
Feb 24 '12 #12
Mihail
759 512MB
Maybe you'll find useful information here:
http://bytes.com/topic/access/answer...el#post3705220
even this thread is yet under work.
Feb 24 '12 #13
NeoPa
32,556 Expert Mod 16PB
That's certainly possible, but nothing really relevant to this thread, which is about getting the DoCmd.TransferSpreadsheet() call to work correctly.
Feb 24 '12 #14

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

Similar topics

2
by: LBT | last post by:
Hi experts, With response.contenttype = "application/vnd.ms-excel", I can easily export my data to Excel which is embeded and shown within a browser. If I'm going to save the Excel file...
1
by: Infinito | last post by:
It's possible to encapsulate Excel in a Access Form so that I can write on the EXCEL sheet? Thanks
18
by: John Bailo | last post by:
I want to write an Excel file (.xls format) from some database data. I don't want to use Excel.exe because of all the automation and security issues. Does Microsoft document the .xls file...
8
by: cgrider | last post by:
I have an access databae that I am creating to import data from the end user from an excel file. And from that generate a report for him to send to a customer. The issue that I am having the report...
0
by: radraq | last post by:
Hello, I have just completed a survey in excel which I've uploaded to my website. The propblem is I would like the excel file to open directly online without asking for paswords and save the...
2
by: radraq | last post by:
Hello, I have just completed a survey in excel which I've uploaded to my website. The propblem is I would like the excel file to open directly online without asking for paswords and save the...
0
by: Supermansteel | last post by:
I have created an Form and Input sheet to be able to input Pricing informtion for 1st and 2nd Mortgages. However, I have recently come accross that there are about 13 states that have different...
6
by: brunpam | last post by:
Hello, I'm somewhat new to Access and I'm trying to open an Excel file from an Acess form command button. The only problem is the Excel filename includes a date and the date changes on a weekly...
1
Soniad
by: Soniad | last post by:
Hi, I want to open an excel file from ASP Page, direclty. Means, Now I can open excel file on onclick by giving its path. But,it's prompting a dialog box with "Open/Save/Cancel" Option. ...
2
by: Kartheepan | last post by:
How to import the excel file in vb form ?
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
isladogs
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...
0
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...
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...
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...

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.