Solved

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

Posted on 2002-03-21
5
391 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
  • 3
5 Comments
 
LVL 1

Expert Comment

by:CareyMBilyeu
Comment Utility
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
Comment Utility
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
Comment Utility
Hey THeine:

Any Luck on this???
0
 
LVL 54

Expert Comment

by:nico5038
Comment Utility
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
Comment Utility
Per recommendation, points NOT refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now