473,473 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating complex spreadsheet from within Access

2 New Member
Hello everyone, long time reader first time poster. I have a question that I can not currently find on my own.

I don't want to go into an overexplanation, but I need to be able to create a workbook that I does roughly the following things:

1) I have a very specific template that the sheets must follow. For example, There is a consistent header and footer the output must have, with a maximum of 15 rows per (printed) sheet. There are other tweaks I must do, but I believe I can handle that on my own. But essentially I need to be able to set individual cell properties, including values (in some cases the values need to be from the query) and row/collumn sizes/borders.

2) Groups rows by one of the collumn's values, and create an individual worksheet for each of these rows. This means that all 15 of the entries with a FieldX value of "apples" will be in the "apples" worksheet, and the 7 entries with a FieldX value of "pickles" will be in the "pickles" worksheet.

3) The worksheets need to be alphanumeric order so when they go to print they will print in order.

In the end I want to be able to have the user click an "output/print" button they can press. Doing so will take a Query/Table's information, and output it into one excel spreadsheet which fills in everything and they are able to print. This will save about 2 hours of gruntwork each time we need to print out a set, not to mention time saved when things need to be changed.

If you all need more information let me know. I will check back for replies ASAP. Thanks!
Feb 27 '07 #1
3 2038
nico5038
3,080 Recognized Expert Specialist
Hmm, will be a daunting task, as Access can't do this without VBA code.

Found this sample on the web:
Expand|Select|Wrap|Line Numbers
  1. Function fncPopulateExcel() As String
  2.  
  3. Private Const XLT_LOCATION As String = "W:\Reports\Database\Request.xlt"
  4.  
  5. On Error GoTo Populate_Err
  6.  
  7.     Dim db As Database
  8.     Dim qdf As QueryDef
  9.     Dim prm As Parameter
  10.     Dim rs As Recordset
  11.     Dim objXL As Object, objSheet As Object, objRange As Object
  12.     Dim strSaveAs As String, strRecord As String
  13.     Dim x As Integer, intRow As Integer
  14.  
  15.     DoCmd.Hourglass True
  16.     Set db = CurrentDb()
  17.  
  18.     ' Open, and make visible the Excel Template (Request.xlt)
  19. Set objXL = GetObject(XLT_LOCATION)
  20.  
  21. objXL.Application.Visible = True
  22. objXL.Parent.Windows(1).Visible = True
  23.  
  24.     ' Open the recordset, and activate the sheet in the template
  25.  Set qdf = db.QueryDefs("qryRequest")
  26.  For Each prm In qdf.Parameters
  27.    prm.Value = Eval(prm.Name)
  28.    Next prm
  29.  
  30.    Set rs = qdf.OpenRecordset(dbOpenSnapshot)
  31.     Set objSheet = objXL.Worksheets("TNSS")
  32.     objSheet.Activate
  33.     rs.MoveFirst
  34.  
  35.     ' Insert the data from the recordset into the worksheet
  36.  
  37. objXL.ActiveSheet.Cells(1, 5).Value = rs![Type]
  38.  
  39. objXL.ActiveSheet.Cells(3, 2).Value = rs![ProjectTitle]
  40.  
  41. ' Set the save string, and save the spreadsheet. The file is saved with the project title as its name. (rs![ProjectTitle])
  42.  
  43.         strSaveAs = "W:\Reports\TimingRequests\" & rs![ProjectTitle] & ".xls"
  44.         objXL.SaveCopyAs strSaveAs
  45.       PopulateExcel = strSaveAs
  46.           rs.Close
  47.  
  48.     'Quit Excel
  49.     objXL.Application.Visible = True
  50.     objXL.Parent.Windows(1).Visible = True
  51.     objXL.Application.DisplayAlerts = False
  52.     objXL.Application.Quit
  53.  
  54.     Set objXL = Nothing
  55.     Set objSheet = Nothing
  56.     Set objRange = Nothing
  57.     Set rs = Nothing
  58. end Function
  59.  
It gives the rough structure. You'll need to add an additional recordsource to loop through the sheets needed for the different fruits, but it's a start.

Let me know when and where you get stuck.

Nic;o)
Feb 28 '07 #2
NeoPa
32,556 Recognized Expert Moderator MVP
The code Nico posted uses these techniques, so you won't necessarily need this, but jic I thought I'd post the link (Application Automation). It's fairly brief but does cover the fundamental concepts so may help you understand what's happening if you're new to it.
Mar 1 '07 #3
Rivulent
2 New Member
Thanks for the suggestion and sample. I figure I would have to work within VBA to do this, which I have no problem doing.

I will take a look at this when i get more free time.. probably this weekend or next. I will post an update when I get to the next stopping point.

Thanks again!
Mar 1 '07 #4

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

Similar topics

5
by: Alan | last post by:
Hi there, Are there Excel charting gurus here?? If so then please read on... Sorry for the cross-post but I'm not familiar with the Excel groups. I've posted to asp.general because if I have...
8
by: Colleyville Alan | last post by:
I have been working on an Access app that takes info from a file and writes it to a spreadsheet on a form, simultaneously saving the spreadsheet to Excel. I got the idea that the same concept...
6
by: someguy | last post by:
Hi, I'm trying to accomplish the following on a form on which i have removed navigational buttons (I apologize in advance if this is too many questions); The two easy ones are.... 1) When...
1
by: jquest | last post by:
Hi; I have a database that keeps track of customers and work done for them. Some customers are repeat customers many times over, ie more than 100 records for them. I keep track of them in the...
13
by: Dixie | last post by:
How do I, in VBA from an access form module, add 5 rows to the top of a spreadsheet called MySpreadsheet.xls. The worksheet is called MyWorksheet and there is already data in the first 5 rows. I...
9
by: Gordon | last post by:
Hello again, Sorry to repost this request, but I'm under a bit of pressure to find a quick solution. All I basically want is an automatically updating link (OLE, not DDE) between a control in...
1
by: Mitch | last post by:
I am using Access to create an Excel spreadsheets with graphs related to rows on the sheet1 to the graph on sheet2. I am using the same data but different subsets of the data to make different...
0
by: sradoff | last post by:
I wish to use XPath to access data from within an Excel generated XML Spreadsheet (generated with MS Excel 2003). I am using an asp Web page (not .NET, not at this time). I instantiate...
3
by: Widge | last post by:
I have made a spreadsheet that will calculate the distance from a set of addresses to a specified postcode in Excel. I'm looking to move this to Access so I can start thinking about hooking it up to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
1
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.