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

Looking for an efficient way to build a report

Hi,

Please see the attached file, which tells a big part of my story. The numbers represent the number of folks who answered "Y" to each question, based on race and gender. There could be thousands of lines of data as well as a few more race/gender combinations.

I'm looking for an efficient way to get from the data example to the report. I know I can create a table that looks like the report example the hard way (an update query for every race/gender combination). From there I can build the report but there has to be a better way.

I need help with either an easier way to get the data in a format similar to the report example or to skip the whole reformat step and go straight to the report. I can imagine the first could be done but, although the second would be preferable, I'm not smart enough to know if it's even doable.

I'd appreciate any help you could offer!

Thanks,
Shawn
Attached Files
File Type: xlsx Table layout.xlsx (8.4 KB, 176 views)
Oct 8 '16 #1
5 916
PhilOfWalton
1,430 Expert 1GB
As I couldn't open your file, I have no idea what you want. Perhaps if you tried zipping it and re-sending someone might be able to help.

Phil
Oct 9 '16 #2
Oralloy
988 Expert 512MB
Shawn29316,

Is there any reason that you need to execute an update query?

What prevents you from building the required view of your database, and then use that as the basis of your report?

Alternately, as a view is just a (sometimes updatable) query, you can just build your query as a stored query and base the report on that.

Or, am I missing something obvious?

Cheers,
Oralloy
Oct 9 '16 #3
Oralloy,

I noticed by your name there's an "expert" tag. That obviously doesn't describe me so there may be a simple way to do this which I just don't know.

My logic for the queries was to use one to create a table containing the question number and a blank field for each race/gender combination. Then there would be an update query for each column to add the data for each race/gender combination.

Thanks for you willingness to help!

Shawn
Oct 9 '16 #4
PhilOfWalton
1,430 Expert 1GB
I think this might help.

Table 6 is made by copying your Excel file into a new table.

table 7 must be defined exactly as this image



Then use the following code

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Function ChangeLayout()
  5.  
  6.     Dim MyDb As Database
  7.     Dim InSet As Recordset, OutSet As Recordset
  8.     Dim i As Integer
  9.     Dim TestInt As Integer
  10.     Dim FieldValue As Variant
  11.     Dim FieldName As String
  12.  
  13.     On Error GoTo ChangeLayout_Err
  14.  
  15.     Set MyDb = CurrentDb
  16.     Set InSet = MyDb.OpenRecordset("SELECT Table6.* FROM Table6;")
  17.     Set OutSet = MyDb.OpenRecordset("SELECT Table7.* FROM Table7;")
  18.  
  19.     With InSet
  20.         Do Until .EOF
  21.             OutSet.AddNew
  22.             For i = 1 To .Fields.Count - 1      ' ignore first field (ID in new table)
  23.                 FieldValue = .Fields(i)
  24.                 If Left(FieldValue, 8) = "Question" Then
  25.                     FieldName = "Question"
  26.                     FieldValue = Mid(.Fields(i), 10)    ' Number after question
  27.                 Else
  28.                     FieldValue = .Fields(i)
  29.                     OutSet.MoveLast
  30.                     OutSet.Edit
  31.                 End If
  32.                 TestInt = CInt(FieldValue)              ' Gives an error for the field name fields
  33.                 OutSet.Fields(FieldName) = Nz(FieldValue)
  34.                 OutSet.Update
  35. NextField:
  36.             Next i
  37.             .MoveNext
  38.             OutSet.Requery
  39.         Loop
  40.         .Close
  41.         Set InSet = Nothing
  42.     End With
  43.  
  44.  
  45. ChangeLayout_Exit:
  46.     Exit Function
  47.  
  48. ChangeLayout_Err:
  49.     If Err = 13 Then                    ' Failed to convert text to number
  50.         FieldName = FieldValue
  51.         Resume NextField
  52.     ElseIf Err = 3020 Then              ' No value
  53.         Resume NextField
  54.     Else
  55.         MsgBox Err & " " & Err.Description
  56.     End If
  57.  
  58. End Function
  59.  
  60.  
Phil
Oct 10 '16 #5
Oralloy
988 Expert 512MB
Shawn29316,

Does PhilOfWalton's example get you off of the ground?

Oralloy
Oct 11 '16 #6

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

Similar topics

2
by: osgnamah | last post by:
Hi All; I am getting ready to launch a shareware program in the next few weeks and the last step is going to be creating a website. So the last few days I've been doing some web surfing in...
2
by: | last post by:
Hello. As I know the crystal report is part of visual studio. 1.When I open a new project I don't have the Crystal Report option. I have C#,C++,V.B,Setup & deployment and visual studio solutions,...
5
by: AstronusX | last post by:
Hi, I'm looking for good printing/reporting tool that customize base on user need, like add more columns to report(design at run-time) for the products that we make? Any recommendation?? Thank...
1
by: Wayne Aprato | last post by:
I've just spent about an hour reading posts on exporting reports as snapshots but still can't find a solution to my exact problem. If I am looking at a report in preview mode and want to click a...
4
by: Brenda | last post by:
I would like to know how to make a report longer than the default 2 1/2 pages. Can this be done with sub reports? I would like to be able to make a 15 page report previewable. Thank you for all...
12
by: mvsguy | last post by:
I'm an Access noob and apologize if I'm asking a stupid question. The problem is that I'm unable to design/preview reports on a database. How do I go about fixing this? Background - A user has...
4
by: BrianDH | last post by:
Hi I am working on a C# Windows Application that builds an invoice (CR) converts to PDF and attach to email one at a time. This works untill my invoice count get over 40 to 50 invoices then I...
12
by: Orchid | last post by:
Hello all, I have different version of reports which used for different months. For example, I am using report version 1 up to September, but we have some design changes on the report for October,...
3
by: jambonjamasb | last post by:
Hi I have two tables: email_tbl Data_table Data table is is used to create a Form Data_form
8
by: Sean Tech | last post by:
Hello, I am currently working on a sales tracking report and could use some assistance. Currently I have a form that the user opens and picks a week date to view the report. In the form there is...
0
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,...
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...
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
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,...

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.