473,804 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do i export a complicated Access subform to Excel

4 New Member
I really need help with this code. I have made a pretty complicated subform that automatically updates filter criteria based off of inputs in various fields within the search form.

What I need to do is design a command button that will kick out the information that is stored in the subform to an excel document. Ideally I would like to use the DoCmd.OutputTo function so that the user could choose their output type, but right now I'll take whatever I can get.

The code for my form is as follows. I use setlink to set the child and master relationships between the form and subform. The control source for my subform is a table named Master Table subform4. And the Record Source for the main search form is a form named SearchFormTable .

Expand|Select|Wrap|Line Numbers
  1. Private Sub setlink()
  2. Dim link As String
  3. Dim found As Boolean
  4.  
  5.  
  6. If Len(Form.Controls("Location").Value) <> 0 Then
  7. If found Then link = link + ";"
  8. link = link + "Location"
  9. found = True
  10. End If
  11. If Len(Model.Value) <> 0 Then
  12. If found Then link = link + ";"
  13. link = link + "Model"
  14. found = True
  15. End If
............I repeat the above code over and over for each of the over 60 different search controls within the form......

Expand|Select|Wrap|Line Numbers
  1. If Form.Controls("PARTS BIN").Value Then
  2. If found Then link = link + ";"
  3. link = link + "PARTS BIN"
  4. found = True
  5. End If
  6.  
  7. If Form.Controls("JJ KELLER").Value Then
  8. If found Then link = link + ";"
  9. link = link + "JJ KELLER"
  10. found = True
  11. End If
  12.  
  13. searchsub.LinkMasterFields = ""
  14. searchsub.LinkChildFields = ""
  15.  
  16. searchsub.LinkChildFields = link
  17. searchsub.LinkMasterFields = link
  18. End Sub
Here is the code that activate the filtering. Again, it is repeated for each of the items.

[code]Private Sub ADOBE_ELEMENTS_ AfterUpdate()
setlink
End Sub

Private Sub BARTENDER_After Update()
setlink
End Sub

Private Sub BUILD_A_BADGE_A fterUpdate()
setlink
End Sub............ ...[code]

Here is my current code for exporting. This is probably the worst written of my attempts, but I got desperate.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Export_Click()
  2.  
  3. Dim stdocname As String
  4. stdocname = "searchsub"
  5. DoCmd.OutputTo acForm, stdocname
  6.  
  7. End Sub

I'm not sure the best route to tackle this. OutputTo will only work with a Form, Table, or Query. Maybe if there is a way to store my subform into a temporary table and OutputTO that. I'm just spit balling here. If anyone can help with this I would really use it. Again, like I said, I know its a challenge, but I like the way the form autocorrects after each change without using a command button to filter. Please help
Jul 22 '08 #1
7 4673
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi. I have added code tags to help delineate your code more clearly above.

I would suggest a fundamental rethink in this case. Mainform/subform structures usually reflect 1 to many relationships, but from the wide ranging nature of what is in your code there does not appear to be such a simple relationship here. Could you tell us what this is about? It looks like some kind of all-encompassing filter by form on everything that possibly might want to be filtered - and 60 possible search controls is complexity beyond any possible user I know of...

if you want to export data to Excel (or any other application) the norm is to build a query first. Not in code, just using SQL or the Access query editor. After that, use filter by form to restrict the data in that query for export. This can be done in code, responding to user selections and so on from the After Update events of the textboxes etc concerned.

I am very unclear indeed why you are linking the subform in code.

-Stewart
Jul 23 '08 #2
TinyTom
4 New Member
Believe me, my life would be alot easier if there the data I am searching in this form had relationships. Unfortunately, primary keys are next to impossible aside from a serial number. Computer names can apply to multiple systems as can all other criteria.

If I'm understanding your suggestion correctly, you advise me to abandon the auto filtering and work on a filter query that is conditional upon the items in the form. Unfortunately, the setlink function that I wrote is what is adding the extra functionality to my form. With the code any user can switch objects and mess around with conditions easily without having to select everything and then try and push the "filter" button. Please advise if there is any way to do it this way.

If not, I guess I can try and make a link to a second form that will use the values in my original form to make an export. Please instruct on how to do it your way. Keep in mind I have around 10 combo boxes, 6 text fields, and over 50 check boxes that limit the search criteria (it is a very large database).
Jul 23 '08 #3
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi TinyTom. Sorry to say I am still none the wiser what it is you are doing; you mention serial numbers and computers - some kind of help desk system or tracking system for PCs and their components?

The next thing that springs to mind is what is the table structure? Where is the hierarchy of objects related to other objects one would expect when modelling PCs, for instance?

If there are no relations defined, and everything is in one big non-relational table, there is no chance at all of resolving such complexity into manageable chunks.

I would be happy to advise you how to move this one forward, but I simply don't have an understanding of what it is you are trying to achieve. My gut feel is that if the design does not adequately model the reality the design has to be changed until it does, which will save an awful lot of rescue effort in the longer run.

-Stewart
Jul 23 '08 #4
TinyTom
4 New Member
I'm taking this table over from the previous developer. The database is a PC inventory database. The old design was, for the most part, one gigantic master table that stored: location (by city), computer name, user name, serial number, job function, status (online, offline, retired), cpu, dual core yes/no column, model, make, software1, software2, software3,softw are4 and a made up primary key that has no relavence besides assigning an indepent identifier.

This table had no relationships to other tables and no primary key assigned. I assigned the serial as the primary key seeing as it was a unique value. From there, I did my best to transfer the software into a new Software table that I related back to the master table with the serial number. In this table I have made around 50 possible checkboxes for software.

Converting the preexisting data into that software table is next to impossible seeing as there is no logic to the previous table. Software names can be located in any of the 4 columns, plus only allowing 4 columns limits the amount of info that can be put into the database.

So I am trying to do my best to work with what I have. Please let me know what you recommend I do to ammend this problem.

The current form with the subform is a search form which allows the user to navigate through the master/software tables to narrow down a search. If the computer they aren't looking for isn't found within the search, there is an "add record" command button that takes them to a data input form that pulls all the info that they already entered into the new form. These temporary values are stored in a table called SearchFormTable . SearchFormTable is the record source for the Search form. Master Table subform4 is the source object for the subform within Search.

The search controls are in 4 tabs within the form header section of Search. The subform is in the detail section.

If there is any detail that you need that I did not describe please let me know.
Jul 23 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi TinyTom. This is a very helpful expansion of your previous post - many thanks.

OK, so you took over a single-table mess that was I would bet originally developed in Excel (which lends itself to such single-table non-database solutions) then imported into Access. However, as the quote below tells me, if you have 50 checkboxes for software you have yourself not created a relational table for software - you appear to have specified the possible software products column by column as yes/no columns in your table (hence you are referring in post 1 to things like Adobe Elements and so on). This means your table is not yet in first normal form (no repeated groups), never mind normalised to third normal (3NF) or Boyce-Codd Normal Form (BCNF).

From there, I did my best to transfer the software into a new Software table that I related back to the master table with the serial number. In this table I have made around 50 possible checkboxes for software.
3NF is essential if you are to use the database's relationships to assist you. The following howto article introduces database normalisation and table structures.

As an aside, relational designs are typically quite narrow in terms of number of columns (table attributes), but deeper in terms of number of rows (individual records). Substituting records as table attributes will hamper you to the point of making your project impossible, and hide the other relationships which exist between the tables.

In my opinion, the likely attributes of your software table would include Product ID (Primary Key (PK), potentially alpha), Supplier Code (Foreign Key (FK), alpha), Product name (alpha), licence renewal date (date/time), Date of Purchase (date time), number of licences (integer) and so on.

This relates 1-m to an Installation table which would list the PCs on which that software was installed: Product ID (FK, from Software), PC Serial No (FK, alpha) (Both FKs forming compound PK of the Installation table), Date Installed (date/time), Date Removed (date/time).

There is also an m-1 relationship from Software to a simple supplier table: Supplier Code (PK, alpha), Supplier Name (alpha)

Spending just a few minutes on this problem identifies three tables apart from your PC table: Supplier, Software, Installation, and PC.

It is usually possible to convert data from an apparently unstructured single table into relational data. I do this using Excel as an intermediate means of working with tabular data and for its ability to replicate values down columns quickly.

If you export the data from Access to Excel you can use Autofilter to find groups of specific values (such as Adobe Elements). You first add a new column to the table called Software ID that eventually will form part of the Installation key of your new installation table. This is done simply by assigning to all rows which contain Photoshop Elements the new Elements software code from the (properly defined) software table. You just need to filter for the word Elements, type in the new product code once, and copy it down all other occurrences.

You go on adding new columns as necessary to reflect parts of the new design. This leads to a big non-relational table in which you have identified new columns which, when extracted, will form the many-side elements of the new 1-m tables you have identified. Then you separate these into individual worksheets which will form the Installation, Supplier and other tables, copy these to Access, and begin the work of defining the relationships between the tables properly.

I am not having you on when I say that this will pay dividends - I can see no prospect of doing anything useful with Access unless you resolve the fundamental design problems that are apparent.

As colleagues on this forum would no doubt confirm, you really, really cannot work with non-relational data as you are doing - you will not find you can get meaningful results from a relational database unless you have relational data to work on.

-Stewart
Jul 23 '08 #6
TinyTom
4 New Member
I really appreciate all the help and advice. I'm doing my best to normalize this database and think that I'm on the right track. I do however need help with my add record button.

I now need the add record button to add the information on the one input for into all of the corresponding tables that now exist. I believe there are 5 of them. What is the coding or method to do this?
Jul 28 '08 #7
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi TinyTom. I'm glad your efforts to normalise the DB are progressing.

As I've mentioned previously, in setting up tables from non-relational data I work manually, by copying and pasting to and from Excel. I generally don't do one-off tasks in code - because it is quicker dealing with it manually than coding it.

If you are looking for ideas related to your first post in this thread, taking the data in your subform and populating other tables with that data, there is a way to do so but it is messy and requires processing of two recordsets simultaneously. With your data being what it is we can only give a skeleton idea below:

Expand|Select|Wrap|Line Numbers
  1. Dim subformRS as DAO.recordset
  2. Dim othertableRS as DAO.recordset
  3. Set subformRS = Me.yoursubform_controlname.form.recordsetclone
  4. set othertableRS = CurrentDB.OpenRecordset ("name of a table you want to add records to")
  5. While not subformRS.EOF
  6.     othertableRS.Addnew
  7.     othertableRS![fieldname1] = subformRS![corresponding field1]
  8.     othertableRS![fieldname2] = subformRS![corresponding field2]
  9.     ...
  10.     othertableRS![fieldnameN] = subformRS![corresponding fieldN]
  11.     othertableRS.Update
  12.     subformRS.movenext
  13. End While
  14. subformRS.Close
  15. othertableRS.Close
This code skeleton uses DAO recordsets. To use DAO please make sure there is a reference to the Microsoft DAO 3.6 Object Library (or later) - from the VB editor select Tools, References and ensure the entry for this is checked.

The code uses RecordsetClone to copy the subform's current recordset at the point you run it - so it will take account of the results of all filtering and so on. It then loops through all records in the cloned dataset and adds records to another table, setting field values for the new records to corresponding values in your subform's dataset. You need to specify the field names of all fields involved - hence why I can only provide you with a skeleton of the code.

This code is not limited to copying one recordset at a time - you can open several others to copy records simultaneously if you wish, as long as these are closed correctly after loop completion. However, for test purposes you may well wish to work with just one copy table to begin with.

Recordsetclone is a very handy way to get access to the underlying recordset data for a form. Unfortunately, it cannot be used directly with methods such as DoCmd.OutputTo to export the entire recordset in one go, as these methods operate on tables and queries (which in Access object terms are tabledef and querydef objects, related to but not the same as the recordset object created by RecordsetClone) .

-Stewart
Jul 29 '08 #8

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

Similar topics

4
14795
by: Paolo | last post by:
Friends, I need help with some code to export different tables to a single spreadsheet in Excel. My excel file is named REPORT and the spreadsheet is named CLIENTS. I do have the code to export a single table to Excel but have problems with multimple tables. Thanks.
14
6455
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD for Oracle, it's possible to force an additional comma delimiter after the last column, if the column is empty on a particular row. Oracle requires this additional comma on empty rightmost columns, for importing purposes.
3
2986
by: Sachin Salgarkar | last post by:
I have a DataSet that I need to export to Excel. The dataset has multiple tables. I need a way to export the complete dataset to a single Excel Workbook with sheets for each table in the dataset. Is that possible ? I have seen solutions that export a single table to an Excel file. Opening the XML ( DataSet.getXML() ) in Excel is a little complicated for our users. Besides , the XML mappings are on the same sheet.
9
10917
by: cassey14 | last post by:
Hi everyone! I really need your help.. I have a search form..And in that search form I have a subform..When they search, the results will display in the subform..I want to export to excel the result in the subform based on the query they search.. Thank you in advance -cassey
5
31927
by: Simon | last post by:
Dear reader, With the export command you can export a query to Excel. By activate this command a form pop's up with the following text:
1
9780
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm having I'd be most appreciative. The database is already constructed, I'm just wanting to export the data to an excel file. In short, I'm hoping to export two Tables (or queries...not sure which to use - they both seem to have the same data) in...
1
10513
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am trying to export to Excel using a command in an Access Form. RowID strFY AccountID CostElementWBS 1 2008 1 7 2 2008 1 7 I want to...
0
1271
by: beebelbrox | last post by:
Greetings all. Once more I must dip into the font of your collective wisdom and request help: I have been given the task of taking an exsisting Access Query and exporting it to excel. There are hitches. The query has two groups of records "A" and "B". The excel spread sheet needs to display Group "A" followed by the subtotals for select fields. Next a little white space then Group "B", again followed by sub totals. With Grand totals...
3
7168
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have a question for you. I have a .csv file which has many lines of data. Each line has many data fields which are delimited by ",". Now I need to extract part of data from this file but save it as an excel file. The data in this excel file will be imported into an Access database. The
0
9712
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
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9171
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
7634
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
6862
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5530
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
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
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.