Results 1 to 3 of 3

Thread: Strange problem in vb

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2004
    Posts
    260

    Strange problem in vb

    Dear friend i make a module which open a crystal report in vb 6.0 .

    The report works fine for first time but for second time it hangs. i have to restart the software every time to get the report. below is my code.


    Code:
    Option Explicit
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    
    
    Private Sub Form_Load()
    
    
    Dim Appl As New CRAXDRT.Application
    Dim Report As New CRAXDRT.Report
    
    
     
     CrystalActiveXReportViewer1.Top = 0
     CrystalActiveXReportViewer1.Left = 0
     CrystalActiveXReportViewer1.Height = 12336
     CrystalActiveXReportViewer1.Width = 15408
     Set Report = Appl.OpenReport(App.path & "\PO_Report.rpt")
     cn.CursorLocation = adUseClient
     cn.ConnectionString = "Provider=SQLOLEDB.1;Password=mypass;Persist Security Info=True;User ID=myid;Initial Catalog=abc;Data Source=my.dummy.com"
     cn.Open
     rs.CursorLocation = adUseClient
     rs.Open "Select * from rpt_PUR_rm_order", cn, adOpenDynamic, adLockReadOnly, adCmdText
     Report.DiscardSavedData
     Report.Database.SetDataSource rs
    
     CrystalActiveXReportViewer1.ReportSource = Report
     CrystalActiveXReportViewer1.ViewReport
     
     
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    Unload frmReport_module
    If rs.State = 1 Then rs.Close
     If cn.State = 1 Then cn.Close
     
     'Set App1 = Nothing
     
     Set rs = Nothing
     Set cn = Nothing
     
     Set frmReport_module = Nothing
    End Sub

    can anyone tell me what is the error in this report. why the whole software needs to be restarted to get the report each time.


    thanks in advance

    Shiv Preet

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Strange problem in vb

    Quote Originally Posted by SHIVPREET2K1 View Post
    can anyone tell me what is the error in this report. why the whole software needs to be restarted to get the report each time.
    There is no error - it works exactly as it was instructed by the programmer (you perhaps?).
    The reason you have to restart your program is because report gets loaded when you load your form [ Private Sub Form_Load() ].
    Instead if you add command button and copy (basically cut/paste) code from form_load to Command1_Click (or whatever button name will be) you will be able to run your report without restarting entire program.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Strange problem in vb

    Moved To Reporting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width