?
Solved

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

Posted on 2002-03-21
5
Medium Priority
?
412 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
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

850 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