Solved

csv files

Posted on 1998-09-10
15
521 Views
Last Modified: 2008-01-16
I am working on a VB program that needs to use  a Crystal Report to print out a .CSV file.  Can this be done?  If so, how?
0
Comment
Question by:Amanda080598
  • 7
  • 7
15 Comments
 
LVL 1

Expert Comment

by:bharris1
ID: 1434055
I don't know about using CR to do it, but the following code is the way I've always created .csv files:

lfreefile = FreeFile
Open "outfile.txt" For Output As #lfreefile
Write #lfreefile, val1, val2, val3, val4,.....
Close #lfreefile


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434056
By CSV can I assume you mean comma seperated values?
If so, yes Crystal Reports can export to that.

As I'm not 100% sure this is what you mean, I am submitting this as a comment.  If it solves your problem, let me know and I'll resubmit it as an answer.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434057
Oops, forgot the how part.

  CrystalReport1.PrintFileName = "TestFile.csv"
  CrystalReport1.PrintFileType = 4
  CrystalReport1.Action = 1

0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:Amanda080598
ID: 1434058
clifABB,

I tried your code, but I am getting a debug message which points to CrystalReport1.Action = 1 with an error message "Invalid report file name."  Please help me locate the problem.  Thank you!
0
 

Author Comment

by:Amanda080598
ID: 1434059
clifABB,

Please explain why you used 4 after PrintFileType and 1 after Action.

Thank you!
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434060
You need to specify the crystal report you want to export.  Do you have that file (rpt file) already created?  If so, you need to add the following code before the three lines above:

CrystalReport1.ReportFileName = "MyReport.rpt" 'This is the name of the report file you created with Crystal Reports
CrystalReport1.Destination = 2 ' File


0
 

Author Comment

by:Amanda080598
ID: 1434061
clifABB,


I am new to all this.

I have a file (.csv) that has to be printed as a report.  When I try to create a report in CR, it doesn't recognize a .csv file as a valid database/source.

How do I create a report from a .csv file and print it?

Thank you!

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434062
Create the report in Crystal.  When you save it, it will be saved as an rpt file.  You will use this file within VB as noted above.
Crystal doesn't actually create csv files, however, using the code above, you can export to a csv file.
0
 

Author Comment

by:Amanda080598
ID: 1434063
The .csv file has already been created in the VB application.  What I need to do is use the CR to print the .csv file while the application is running.  I used a CR control with your code.  The application will have a print button which will print the .csv file in a CR report format.   How would I do this ?  
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434064
Oh, I see.  Excuse me for not understanding before.

You must first create an ODBC connection to your csv file.

To do this, you must start your ODBC administrator.  This can be found in the control panel.
To add a new connection, Click "Add" And then select "Microsoft Text Driver" from the list.  Then click Finish.

Type the Data Source name (which is what you want to appear in the ODBC list)
Uncheck "Use Current Directory" then click the "Select Directory" button and select the directory where your csv file exists.
Click Ok, and click Ok.

Now, start your Crystal Report Designer.  Select the type of report you want.  Now the select database screen appears.  Select SQL/ODBC which will display a list of the ODBC drivers available.  Select ODBC - Text Files from the list.  Click Ok and you're on your way.
0
 

Author Comment

by:Amanda080598
ID: 1434065
clifABB,

Thank you for the information above.  I completed entering all the information, but when I run the program the CrystalReport1.Action = 1 debugs with an error message <property is write-only>.  Also, error 20514 keeps popping up.

CrystalReport1.ReportFileName = "File001.rpt"
CrystalReport1.Destination = 2 ' File
   
CrystalReport1.PrintFileName = "File001.csv"
   
CrystalReport1.PrintFileType = crptCSV
   
CrystalReport1.Action = 1

Please let me know, if this is correct.

Thank you so much for your help.

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1434066
The original setting I had given you were when I thought you wanted CR to write out a csv.  You should now change those lines to this:
CrystalReport1.ReportFileName = "File001.rpt" 'Or whatever you call the report file you created

CrystalReport1.Destination = 0 'This will allow a print preview.  Or 1 to go to the printer    

CrystalReport1.Action = 1

0
 

Author Comment

by:Amanda080598
ID: 1434067
clifABB,

It worked.  Thank you for all your help!

Please send  your comment as an answer, so  I may grade you.
0
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1434068
I'm glad we finally got it to work.  :)

As requested, here is the official answer:

You must first create an ODBC connection to your csv file.

To do this, you must start your ODBC administrator.  This can be found in the control panel.
To add a new connection, Click "Add" And then select "Microsoft Text Driver" from the list.  Then click Finish.

Type the Data Source name (which is what you want to appear in the ODBC list)
Uncheck "Use Current Directory" then click the "Select Directory" button and select the directory where your csv file exists.
Click Ok, and click Ok.

Now, start your Crystal Report Designer.  Select the type of report you want.  Now the select database screen appears.  Select SQL/ODBC which will display a list of the ODBC drivers available.  Select ODBC - Text Files from the list.  Click Ok and you're on your way.

0
 

Author Comment

by:Amanda080598
ID: 1434069
Adjusted points to 100
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question