Solved

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

Posted on 2002-03-21
5
392 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access 2016 Debugging 7 42
running an update statement after a msgbox (MS Access) 3 31
Library not Registered 16 49
Access Excel export not behaving 2 25
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now