473,657 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CSV Import and show in report

57 New Member
Don't know if this can be done or not but I'm sure the gurus here will let me know ;)

Got a .csv file that is being imported into a table using specs. The table consists of the following:
Issue (text)
Returned_Date (Date/Time)
RD (text)
RM (text)
Region (Text)
Type (text)
ClientName (text)
4398
4399
4400
etc.
The etc. being about 80 addtional numeric column names that represent questions being answered on a survey.

My task in this is to retrieve all the "Yes" answers to these questions by RD and list them in a report.

Currently, I'm looping through the table and pulling these "Yes" records based on a RD chosen from a drop-down box and creating another table with the field names Header, Header1, Header2, up to Header10, which is dependent on
how many clients answered the survey so it looks like this:




Then I'm looping through each Header, one at a time and putting into an unbound control on a report.

Expand|Select|Wrap|Line Numbers
  1. 'First Client 
  2. counter = 1 
  3.  
  4. sql = "GROUP BY tbl90Day.Header, tbl90Day.Header1, tbl_Questions.Question HAVING (((tbl90Day.Header1) Is Not Null)) ORDER BY tbl90Day.Header DESC " 
  5.  
  6. Set ors = New ADODB.Recordset 
  7. ors.ActiveConnection = CurrentProject.Connection 
  8. ors.Open _ 
  9.      Source:="SELECT tbl90Day.Header, tbl90Day.Header1, tbl_Questions.Question FROM tbl_Questions RIGHT JOIN tbl90Day ON tbl_Questions.ID = tbl90Day.Header " & sql, _ 
  10.      LockType:=adLockOptimistic, _ 
  11.      options:=adCmdText 
  12.  
  13. If Not ors.BOF Then ors.MoveFirst 
  14. Do While Not ors.EOF 
  15.  
  16. If ors(0) = "Type" Then 
  17. Report_srpt_CPS90.Text18 = ors(counter) 
  18. ElseIf ors(0) = "CLIENTNAME" Then 
  19. Report_srpt_CPS90.Text10 = ors(counter) 
  20. ElseIf ors(0) = "DATECREATED" Then 
  21. Report_srpt_CPS90.Text21 = ors(counter) 
  22. ElseIf IsNumeric(ors(0)) Then 
  23.     If question1 = "" Then 
  24.     question1 = ors(2) 
  25.     ElseIf question2 = "" Then 
  26.     question2 = ors(2) 
  27.     ElseIf question3 = "" Then 
  28.     question3 = ors(2) 
  29.     End If 
  30. End If 
  31. If Not ors.EOF Then ors.MoveNext 
  32. Loop 
  33.  
  34. Dim strPara1 As String 
  35. strPara1 = question1 & vbCrLf & vbCrLf 
  36. strPara1 = strPara1 & question2 & vbCrLf & vbCrLf 
  37. Report_srpt_CPS90.Text23 = strPara1
  38.  
(The join to tbl_questions is so that the actual question/statement will be shown).

So, at the moment, it is listing 3 of the answers because I've referenced only 3 at this time.

The only problem with this is:
1 - having to do each client one at a time (Header1, Header2, Header3, etc).
2 - There are so many questions so it would become quite long and burdensome to do an elseif on each Client for each question.

Is there a simpler way of doing this?

I was leaning towards an array but I'm not array savy and it just confuses me.

Thanks in advance!
Jun 15 '09 #1
7 2081
NeoPa
32,568 Recognized Expert Moderator MVP
As I don't know what RD refers to I found almost everything after that point almost meaningless. A shame as it seemed very clear up to that point (and you'd clearly put effort into explaining as fully as possible).

Let me see if I can post something helpful anyway. If you need more then I'll check later for a clarified question.

First of all, it seems to me that your data is presented to you in a format that is not designed to enable you to do what is requested. The good news though is that some VBA coding can help to determine the count of the Yeses in all the numeric fields. With a function set up called CountYes() you could have SQL in your query similar to :
Expand|Select|Wrap|Line Numbers
  1. SELECT ...
  2.      , CountYes([4398] & [4399] & [4400] & ... & [4480]) AS CountYs
  3.      , ...
  4.  
  5. FROM   [YourTable]
The function would be quite simple :
Expand|Select|Wrap|Line Numbers
  1. Public Function CountYes(strQs As String) As Integer
  2.     CountYes = Len(strQs) - Len(Replace(strQs, "Yes", "**"))
  3. End Function
Jun 15 '09 #2
NeoPa
32,568 Recognized Expert Moderator MVP
There is another possible approach. It's still code-based, but may be easier to understand for some.

You can create a basic query on the table and use this in code as a RecordSet. In a RecordSet you can access the .Fields collection and process through them all in a loop (For Each ... Next) excluding all other known fields or including only those whose name is made of 4 digits.

This could be done as an update query or a Make-Table query to make the values available generally. There are many options available once you have the basic concept.
Jun 15 '09 #3
DThreadgill
57 New Member
Sorry NeoPa - - I meant to change the fieldnames in the first part before i actually posted. RD = RDNAME as shown in the image. RM = RMName. I guess trying to simplify actually made it worse! :)

Here are the correct field names as imported in my Main table:
Issue (text)
Returned_Date (Date/Time)
RDName (text)
RMName (text)
Region (Text)
Type (text)
ClientName (text)
4398
4399
4400
etc.

You're correct in that the format of the .csv file is definitely NOT designed in my favor but since it's coming from an outside source, I have to make do (or not if not possible). I've already requested changes that they won't make. As it stands, there's a possiblity that if a particular numeric field isn't populated across the board, it won't be exported with their process so my import process is already defunct!

I can get the count with no problem but I have to reveal the actual questions for each client in the report. :)

I think I get the concept of the .fields collection and will work in that direction and see where it takes me.

Hope this clears up my previous post. :)

Any additional ideas will be greatly appreciated
Jun 15 '09 #4
NeoPa
32,568 Recognized Expert Moderator MVP
Ah, so would I be right in thinking you must show all the Yeses with their titles included, but ignore those that aren't Yes?

The .Fields collection would probably be the way to go here I think.
Jun 15 '09 #5
DThreadgill
57 New Member
Bingo! Haven't started on it yet...I'm a procrastinator :) Any problems, I'll sure let ya'll know!

Thanks, NeoPa!!!!
Jun 15 '09 #6
DThreadgill
57 New Member
After a bit of frustration, I finally got the .fields to work :) I appreciate your guidance NeoPa....I'd still be trying to figure out which way to go!!!

As per your suggestion, got the fieldnames using the .field collection and added to a table:

Expand|Select|Wrap|Line Numbers
  1. If Not rs.BOF Then rs.MoveFirst 
  2. Do While Not rs.EOF 
  3.  
  4. For nextfield = 8 To 42 
  5. sql = "Select [Question] from tbl_Questions where [ID]= '" & rs.Fields(nextfield).Name & "'" 
  6. Set ors = CurrentDb.OpenRecordset(sql) 
  7. If rs(nextfield).Value = "Yes" Then 
  8.  
  9. 'Add results to table 
  10. sql = "Select * from tblTmpAllYes" 
  11. Set trs = CurrentDb.OpenRecordset(sql) 
  12.  
  13. trs.AddNew 
  14. trs(0) = rs(0) 'RD Name 
  15. trs(1) = rs(1)  'RM Name 
  16. trs(2) = rs(4)  'Client Name 
  17. trs(3) = rs(2)  'region 
  18. trs(4) = rs(3)  'Area
  19. trs(5) = rs(5) 'Type 
  20. trs(6) = rs(6) 'Date Created 
  21. trs(7) = rs(7) 'Notes 
  22. trs(8) = ors(0) 'Question Title
  23. trs(9) = rs.Fields(nextfield).Name   'Question # 
  24. trs.Update 
  25. End If 
  26.  
  27. If Not ors.EOF Then ors.MoveNext 
  28. Next nextfield 
  29.  
  30. If Not rs.EOF Then rs.MoveNext 
  31. Loop 
Jun 23 '09 #7
NeoPa
32,568 Recognized Expert Moderator MVP
Good for you Dave. Sounds like you have it sussed :)
Jun 23 '09 #8

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

Similar topics

4
3161
by: teddysnips | last post by:
This is a rather abstract question about data design, but I ask it here because a) the database is SQL Server, and b) you're such a learned bunch! Let's assume the classic relation of Customers and Orders, where an Order may reference a single Customer. If I was designing such a relation from scratch, I would create the Customer table with an Identity column and call it CustomerID. The Order table would contain a column called...
1
2684
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a "write to the database", we store the dataset's diffgram in the audit table. To render the audit report we load the diffgram into a generic DataSet and bind it to a grid. All works well unless the document's schema had an <xs:import> to bring...
1
2203
by: Sigurd Bruteig | last post by:
Hi I have made an invoice app.(mde) that are run with Access runtime 2002. Some users want a custom invoice form with logo. What I am looking for is a function to import this custom made report into the application. Then the user will be able to import his own custom made invoice report, that have been reveived by e-mail. Sigurd --
4
3017
by: Steve Jorgensen | last post by:
I'm restarting this thread with a different focus. The project I'm working on now id coming along and will be made to work, and it's too late to start over with a new strategy. Still, I'm not coming to a firm conclusion over whether it was the better approach, and wonder if I should do it differently the next time I'm faced with a similar issue. I needed an app to automatically import from spreadsheets with a semi-dynamic structure,...
7
1788
by: Anne M | last post by:
I have a report based on query..which is a team list with names and their role on team ie coach, assistant and player. Report is almost what I want and my knowledge is limited so I need some advice. I want the team list to show the names of the individuals and their role on team if they are coach or assistant but not if they are player but since they are based on the same field (role) how do I set it so I can get it to show only what...
2
14115
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002 database? Thanks, Dean Slindee
3
3670
by: Jim Vincent | last post by:
Greetings All, Hope you can help me out here. I'm trying to import from Excel but the default date in Excel is in this format: 12/2/2005 12:49:49 AM (for example). What input mask can I use in Access so it will accept it? If it is a challenge, how can I knock it down to just the date? TIA.
7
20552
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 _Ron
4
6229
by: David | last post by:
Hi I'm using this code to import data from an excel spreadsheet: DoCmd.TransferSpreadsheet , acSpreadsheetTypeExcel9, "tblStudents", _ "\\Egusersrv\Staff - Shared Work\PE Teach & Report\Imported Spreadsheets/ImportStudents.xls", True Which works fine if the spreadsheet is always in the pre-defined location. Ideally what I would prefer to do is have the user locate
0
8420
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
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8516
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
7353
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...
0
5642
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
4173
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1733
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.