Crystal Reports XI With Visual Basic 6.0
' Add Form And rename to FrmRepView
' Add Code to Module

VB Code:
  1. Sub ReporView(SQLsentence As String, ViewName As String, ReportName As String)
  2.             On Error Resume Next
  3.             Dim CN As New ADODB.Connection
  4.             Dim rss As New Recordset
  5.             Dim appw As New CRAXDDRT.Application
  6.             Dim rpt As New CRAXDDRT.Report
  7.             Dim tbl As CRAXDDRT.DatabaseTable
  8.             Dim db As New ADODB.Connection
  9.             CN.Execute "Drop View " & ViewName
  10.             CN.Execute "Create View " & ViewName & " as " & SQLsentence
  11.             x = App.Path & "\" & ReportName & ".rpt"
  12.             appw.LogOnServer "crdb_odbc.dll", "GRS", "GRS", "sa", "asd123"
  13.             Set rpt = appw.OpenReport(x)
  14.             rpt.Database.LogOnServer  "crdb_odbc.dll", "GRS", "GRS", "sa", "asd123"
  15.             FrmRepView.show
  16.             FrmRepView.CrystalActiveXReportViewer1.Refresh
  17.             FrmRepView.CrystalActiveXReportViewer1.ReportSource = rpt
  18.             FrmRepView.CrystalActiveXReportViewer1.ViewReport
  19.             ' appw.LogOnServer "crdb_odbc.dll", "GRS", "GRS", "sa", "asd123"
  20.             'DSN=grs;USER ID=sa;pwd=asdsuez;
  21.         End Sub
thes Code Work With Me

But
I Use Sql Server 2000
The problem Is When I Change Database Name
And Cang DSN To New Database

The Report Not View result
And Gev Me Error Logon failure

If Eny own Now The problem Help me please !