Solved

Using a command button in MS Access to open Seagate Crystal Reports

Posted on 2002-03-21
5
400 Views
Last Modified: 2008-02-07
I am using Crystal as a query tool to access client  information from our mainframe.  I would like to launch a Crystal report from Access so the user would not have to use both applications (Access and Crystal) in a disjuncted manner.  The effort here is to use a command button to open a pre-established Crystal report that would look up all of the personal information on one of our clients based on policy number.  The query results from Crystal would then populate in a table in the Access database.  The database used here will track complaints for our company.  Instead of having to type all of the client information manually (and avaoiding data integrity errors) we would like to use the protocol described above.  Do you know if this can be done?  Please let me know if you need more information.  Thanks!
0
Comment
Question by:THeine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Expert Comment

by:CareyMBilyeu
ID: 6885862
You need to place a command button on your form that references the Crystal OCX that you are going to install on the form as well.

You will set the properties of the OCX to the report that you want to open.

Private Sub MyCommand_Click()
Dim mres As String

CrystalReport0.Reset

With CrystalReport0
.ReportFileName = "E:\My Documents\Test.rpt"
.Destination = crptToWindow
mres = .PrintReport
If mres <> 0 Then
MsgBox "Error", vbOKOnly

End If

End With

End Sub


Now you can do plenty of interesting things here, you can pass parameter values, create a query in the call, set group options, etc.

another example:

Sub CrystalReportConnect1 (mCrystalFormName as Form)

Dim SelectionFormula as String
Dim mres as String

CrystalReport0.Reset    'refers to the OCX

CrystalReport0.WindowTitle "Some Title Here"

With CrystalReport0
.Connect = driver={SQL Server};server="MyServer;uid="Me";pwd="sa";database="database";

.ReportFileName= "C:\My Docs\MyReport1"
.ReplaceSelectionFormula {sp_My StoredProcedure}
.Destination = crptToWindow

mres = .PrintReport

If mres <> 0 Then
Do Something Here

End If

End With


If you're using stored procedures, (much faster), you can also Dim the sp name and then do a With statement to update your record set in Access.

Cheers
0
 
LVL 1

Expert Comment

by:CareyMBilyeu
ID: 6889044
THeine:

I have been playing around with the Crystal Reports OCX and can find only several references to the informations that you need;

Start with a command button on your form and place the Crystal Reports Active X control onto the form. Name it CrystalReports1.

We are going to set the code & properties behind the command button, therefore you do not need to set any properties on the OCX other than the name.

Sub MyCommand

Dim myCity As String
myCity = Me!Combo3

CrystalReport1.Reset

With CrystalReport1
.ReportFileName = "E:\My Documents\Test.rpt"
.ParameterFields(0) = "City; " & myCity & ";True"
.Destination = crptToWindow

mres = .PrintReport

If mres <> 0 Then
MsgBox "Error or do something else", vbOKOnly
End If

End Sub

OK, here's what's going on.

I have a combo box on my form to select a city from my Customers table.

I refresh CrystalReports1 by Resetting it.

I tell CrystalReports1 the location and name of the file.

I then pass the parameter "MyCity" to the report by "TRUE".

Then I tell it where to publish the report, in this case, my monitor.

You can tell Crystal Reports to Output the file to and ODBC-MS Access table, including the file that you are working in, BUT, it's not pretty and you will have to perform another query on the data and place the new data into another table. You would be better off coding it to output to a comma seperated value file (Text File) and then perform an import by way of an import specification.

Hereis a sample to set the destination output to a CSV file:

CrystalReport0.Reset


With CrystalReport0
.ReportFileName = "E:\My Documents\Test.rpt"
'.ReplaceSelectionFormula = " & MyCity & "
.ParameterFields(0) = "City; " & myCity & ";True"

.Destination = 2  'crptToFile
.PrintFileCharSepQuote = ""
.PrintFileCharSepSeparator = ","
.PrintFileName = "E:\My Documents\test.csv"
.PrintFileType = 6 - crptCharSep
.ReportFileName = "E:\\My Documents\Test.rpt"


mres = .PrintReport
If mres <> 0 Then
MsgBox "Error", vbOKOnly


Good luck,

Carey

0
 
LVL 1

Expert Comment

by:CareyMBilyeu
ID: 6889428
Hey THeine:

Any Luck on this???
0
 
LVL 54

Expert Comment

by:nico5038
ID: 7062241
for THeine

No comment has been added for the last two months.
So it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
 - PAQ'd and pts removed
Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

Nic;o)
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7080445
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

734 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