I can print current data in Crystal Reports from my application

wardcomm
wardcomm used Ask the Experts™
on
I can't print current data in Crystal Reports from my application? How can I print current data that I am looking at in vb to be sent to crystal reports?

I am using VB6 with the Crystal Reports designer that came with it. I can not print out the current data that I see in vb front end. It will print out what ever one it wants.  I have search all over the internet for an answer.  I have tried

1.) removing the check mark in crystal reports that says to keep data with report. (that did not work)
2.) I have tried command like CrystalReports1.Refresh
"as one site said to try" (that did not work)



----------------------MY CODE---------------------

Private Sub sbStatusBar_Click()

End Sub

Private Sub File1_Click()

End Sub

Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus               'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub



Private Sub cmdDelete_Click()
    'Delete a record
    On Error GoTo DelErr
    With Data1.Recordset
            .Delete
            .MoveNext
        If .EOF Then .MoveLast
    End With
    Exit Sub                        'Disregards the following if no error
DelErr:
    MsgBox Err.Description
End Sub



Private Sub Command1_Click()
CrystalReport2.PrintReport
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Command3_Click()
'CrystalReport1.Destination = crptToWindow
CrystalReport1.DiscardSavedData = 1

'CrystalReport1.Action = 0
CrystalReport1.PrintReport
'CrystalReport1.DiscardSavedData = True

End Sub

Private Sub Image1_Click()

End Sub

Private Sub CRViewer1_CloseButtonClicked(UseDefault As Boolean)

End Sub

Private Sub ConnecttoSupport_Click()
Frm1.Show
End Sub

Private Sub Exit_Click()
End
End Sub

Private Sub ShowDocument_Click()
CrystalReport1.PrintReport
End Sub

-------------------------------------------------
Please help and happy thanksgiving
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Try adding a Data1.refresh before exiting the subroutines where you add or delete.

mlmcc

Author

Commented:
I added the Data1.Refresh in the sub routine as shown below that did not work. It is when I click on the command button that starts crystal reports. Crystal reports show what ever first recordset that i pushed and not what ever is current.

so my question is how do you print the most current data to crystal reports?



Here is what I added
==========================
Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus               'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Data1.Refresh
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub


----------------------------------------------
Private Sub cmdDelete_Click()
    'Delete a record
    On Error GoTo DelErr
    With Data1.Recordset
            .Delete
            .MoveNext
        If .EOF Then .MoveLast
        Data1.Refresh
       
    End With
    Exit Sub                        'Disregards the following if no error
DelErr:
    MsgBox Err.Description
End Sub


Here is my whole program again
=====================================

Private Sub sbStatusBar_Click()

End Sub

Private Sub File1_Click()

End Sub

Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus               'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Data1.Refresh
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub



Private Sub cmdDelete_Click()
    'Delete a record
    On Error GoTo DelErr
    With Data1.Recordset
            .Delete
            .MoveNext
        If .EOF Then .MoveLast
        Data1.Refresh
       
    End With
    Exit Sub                        'Disregards the following if no error
DelErr:
    MsgBox Err.Description
End Sub



Private Sub Command1_Click()
CrystalReport2.PrintReport
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Command3_Click()
Data1.Refresh
'CrystalReport1.Destination = crptToWindow
CrystalReport1.DiscardSavedData = 1

'CrystalReport1.Action = 0
CrystalReport1.PrintReport
'CrystalReport1.DiscardSavedData = True

End Sub

Private Sub Image1_Click()

End Sub

Private Sub CRViewer1_CloseButtonClicked(UseDefault As Boolean)

End Sub

Private Sub ConnecttoSupport_Click()
Frm1.Show
End Sub

Private Sub Exit_Click()
End
End Sub

Private Sub ShowDocument_Click()
CrystalReport1.PrintReport
End Sub

Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Is the form tied to the data1 recordset?  I don't see anywhere where you are really adding records.

CrystalReport1.DiscardSavedData = 1
I think in VB TRUE is -1 try that
CrystalReport1.DiscardSavedData = -1

It might also be you need

Data1.Recordset.Refresh rather than Data1.Refresh

mlmcc
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

Author

Commented:
That did not work either. Yes the form array is tied to my data1 recordset,

My add button:
====================

Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus               'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Data1.Recordset.Refresh
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub
=================================
Delete botton:
===============================
Private Sub cmdDelete_Click()
    'Delete a record
    On Error GoTo DelErr
    With Data1.Recordset
            .Delete
            .MoveNext
        If .EOF Then .MoveLast
        Data1.Recordset.Refresh
       
    End With
    Exit Sub                        'Disregards the following if no error
DelErr:
    MsgBox Err.Description
End Sub
===========================================
Do you know of a vb book that  goes over usable topics like this?

My Program right know:
=================================================

Private Sub sbStatusBar_Click()

End Sub

Private Sub File1_Click()

End Sub

Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus               'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Data1.Recordset.Refresh
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub



Private Sub cmdDelete_Click()
    'Delete a record
    On Error GoTo DelErr
    With Data1.Recordset
            .Delete
            .MoveNext
        If .EOF Then .MoveLast
        Data1.Recordset.Refresh
       
    End With
    Exit Sub                        'Disregards the following if no error
DelErr:
    MsgBox Err.Description
End Sub



Private Sub cmdrefresh_Click()

Data1.Recordset.Refresh

End Sub

Private Sub Command1_Click()
CrystalReport2.PrintReport
End Sub

Private Sub Command2_Click()
Form2.Show
End Sub

Private Sub Command3_Click()
Data1.Recordset.Refresh

'CrystalReport1.Destination = crptToWindow
'CrystalReport1.DiscardSavedData = 1
CrystalReport1.DiscardSavedData = -1
'CrystalReport1.Action = 0
CrystalReport1.PrintReport
'CrystalReport1.DiscardSavedData = True

End Sub

Private Sub Image1_Click()

End Sub

Private Sub CRViewer1_CloseButtonClicked(UseDefault As Boolean)

End Sub

Private Sub ConnecttoSupport_Click()
Frm1.Show
End Sub

Private Sub Exit_Click()
End
End Sub

Private Sub ShowDocument_Click()
CrystalReport1.PrintReport
End Sub

===========================================
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
We are making something too complicated.  I am not seeing the problem.  It looks like it should work.

mlmcc

Author

Commented:
I agree we are making something complicated.

The problem is when I push the command button called "command3_click which calls the Crystal reports
========================
Private Sub Command3_Click()
Data1.Recordset.Refresh

'CrystalReport1.Destination = crptToWindow
'CrystalReport1.DiscardSavedData = 1
'CrystalReport1.Action = 0
'CrystalReport1.DiscardSavedData = True
CrystalReport1.DiscardSavedData = -1
CrystalReport1.PrintReport
================================
the button brings up the CrystalReports viewer. The data that is in the crysal reports is not the current data that I am looking at in the form when I push the button. So My question is, how can this be remedied?
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Are you using the RDC?

You state
"The data that is in the crysal reports is not the current data that I am looking at in the form when I push the button. "

By this do you mean you jave added a record but it isn't reflected in the report?

mlmcc

Author

Commented:
does RDC mean "Report Designer Component", the one that comes on the CD of VB6.0. Then the answer would be yes. If that is the one you are refering to.

 When I stated "The data that is in the crysal reports is not the current data that I am looking at in the form when I push the button." I created a command button and named it command3 ( actually vb did).
 
This is what i have as vb code that is associatied with it:
----------------------------------------------
Private Sub Command3_Click()
Data1.Recordset.Refresh
'CrystalReport1.Destination = crptToWindow
'CrystalReport1.DiscardSavedData = 1
'CrystalReport1.Action = 0
'CrystalReport1.DiscardSavedData = True
CrystalReport1.DiscardSavedData = -1
CrystalReport1.PrintReport
End Sub
--------------------------------------------
The CrystalReport1 is  from Crystalreport component that was added when I added controls cr analyser 1.0 type library,crystal report control 4.6, crystal report viewer control, crystal select expert ole control.

I have add button,delete button, print button,email button,

Let say I type in new data into form textboxes and click add then use the data control to get to that recordset I want and click print which runs this sub routine:

Private Sub Command3_Click()
Data1.Recordset.Refresh
'CrystalReport1.Destination = crptToWindow
'CrystalReport1.DiscardSavedData = 1
'CrystalReport1.Action = 0
'CrystalReport1.DiscardSavedData = True
CrystalReport1.DiscardSavedData = -1
CrystalReport1.PrintReport
End Sub
------------------------
The report pop up fine, but it has data from a recordset I did at another time.

When trying to take specific record out of the database, is there a way to push print and another form comes up that will allow you to pick a specfic recordset and let say pick the primary key from access that will send the data from that form to the crystalreport? I also have crystal report 8.5 loaded but vb6 doesn't like the rpt made from it, should I uninstall it maybe there is .dll that is causing this?

Also I will put a zip file of the program on my website that you can take a look at it. You don't have to but some times looking at the whole problem we could start cutting the problem in half. The URL is http://www.the-it-professionals.com/zipped_programs/Off The Record.zip

By the way thanks for taking time out of your day to help me.


Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
To get CR8.5 to work in your VB program you need to update the references to refer to the CR8.5 dlls rather than the CR4.6 dlls.

Can you open the report?
If so
Open the report
Click FILE
Ensure SAVE DATA WITH REPORT is not checked.
If it is uncheck it and save the report.

Another thought
Change
   Data1.Recordset.AddNew
to
   Data1.Recordset.Update

mlmcc

Author

Commented:
To get CR8.5 to work in your VB program you need to update the references to refer to the CR8.5 dlls rather than the CR4.6 dlls.

So what are the dlls and what is the process. I know it is regsvr32 and the dll but what are the dll. because right know If i use 8.5 to make the rpt. I can't open it with vb, i get an error. is there a website out there that goes over the dlls.

By the way the add button works better with
--------------------------
Private Sub cmdAdd_Click()
    'Add new record
    'txtLName.SetFocus        'Cursor goes to last name
    On Error GoTo AddErr
    Data1.Recordset.AddNew
    Data1.Recordset.Update

    'Data1.Recordset.Refresh
    Exit Sub                        'Disregards the following if no error
AddErr:
    MsgBox Err.Description
End Sub
---------------------
We are almost there. So if I use 8.5 will that fix the problem with updating current data to crystal reports.
If you fix this problem I will go help other people in the forum and give you a lot of points if i can.
Mike McCrackenSenior Consultant
Most Valuable Expert 2011
Top Expert 2013

Commented:
Open the VB program
Select PROJECT --> REFERENCES
Select the CR 8.5 Design Run TIme Library

If it doesn't exist, which edition of CR 8.5 do you have?
Standard, Professional, or Developer?

If you don't have developer you can't use CR8.5 from VB.

mlmcc

Author

Commented:
cr8.5 pro there is no CR8.5 Design run time library in project  --> references but there is other is one that says crystal reports 8.5 active x designer runtime library,and crystal reports 8.5 standard wizard library,

I added all of the above
I created a test .rpt with 8.5 and pointed the crystalreport1 to the rpt click on. I click on my command button that prints to crystalreports. You can see something pop up and disappear that it.
Senior Consultant
Most Valuable Expert 2011
Top Expert 2013
Commented:
You want
crystal reports 8.5 active x designer runtime library

I didn't have VB & CR loaded on the machine so I was guessing at the name.

mlmcc
This question has been classified abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.


Unless it is clear to me that the question has been answered I will recommend delete. It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.


If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

Pat K
EE Cleanup Volunteer

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: mlmcc {http:#7516807}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

mnye
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial