Hello fubak !!!

type the following at the top of the code in the print button click event:


I am sorry if i am typing it in 2017. But i am happy coz someone may get benefit from this.
Using CrystalReport 8.5 CrystalReport.OCX on vb6 form.
Imaging that the main report also posses one or more sub reports.
You will also see two time Cr.Connect Method don't worry its requirement
one for main report and the other for sub report or reports.

Cr.Connect = "DSN=MyDataSource;UID=sa;PWD=MyPassword;DSQ=MyDatabaseName"
Cr.ReportFileName = App.Path & "\Reports\crv.rpt"
Cr.Destination = crptToWindow
Cr.WindowState = crptMaximized
Cr.WindowTitle = "Bank Payment Voucher"
Cr.DiscardSavedData = True
Cr.SelectionFormula = "{crv_main.sno}=" & txtID.Text

''''''''Also connect any subreports to the proper database'''''''''''''''''''''''''''''''''
nRpt = Cr.GetNSubreports
nCurr = 0
While nCurr < nRpt
szName = Cr.GetNthSubreportName(nCurr)
Cr.SubreportToChange = szName
Cr.Connect = "DSN=MyDataSource;UID=sa;PWD=MyPassword;DSQ=MyDatabaseName"
nCurr = nCurr + 1

'''''''''End of Connect''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Cr.Action = 1