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

CSV Import and show in report

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 2060
NeoPa
32,556 Expert Mod 16PB
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,556 Expert Mod 16PB
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
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,556 Expert Mod 16PB
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
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
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,556 Expert Mod 16PB
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
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...
1
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...
1
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...
4
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...
7
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...
2
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...
3
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...
7
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 ...
4
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 &...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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.