Results 1 to 6 of 6

Thread: Why is it the query doesnt work

  1. #1

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Why is it the query doesnt work

    VB Code:
    1. Dim oapp As CRAXDRT.Application
    2.     Dim oreport As CRAXDRT.Report
    3.     Dim oRs As Recordset
    4.     Dim sSQL As String
    5.  
    6.     Set oRs = New Recordset
    7.     Set oRs = connect.Execute("SELECT * FROM tCommission where contno like '" & NContNo & "'")
    8.     Set oapp = New CRAXDRT.Application
    9.     Set oreport = oapp.OpenReport(App.Path & "\report1.rpt", 1) '\rptCommission
    10.     oreport.Database.SetDataSource oRs, 3, 1
    11.     RptCommission.ReportSource = oreport
    12.     RptCommission.ViewReport


    it always display the first record in the table.. help pls...

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Why is it the query doesnt work

    Normally when you use the Like statement in an SQL query you would also use wildcards. Try this and see if it makes a difference:
    VB Code:
    1. Set oRs = connect.Execute("SELECT * FROM tCommission where contno like '%" & NContNo & "%'")
    Note the percent signs. This SQL would find any contno that contained NContNo.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Why is it the query doesnt work

    thanx for d reply... still.. it doesnt work... by the way, im try a new approach which is using a stored procedure but my problem is the code in vb6... dnt know how to link the crystal report using stored procedure...

  4. #4
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Why is it the query doesnt work

    Sorry. I've never used stored procedures with Crystal so I'm probably not much use to you.

    Good luck.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  5. #5

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Why is it the query doesnt work

    can u tell me how u display ur query in Crystal?

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Why is it the query doesnt work

    Up until very recently I used the Crystal API for reporting, but am now starting to use theCrystal RDC and the Report Viewer. I use 'Selection Formulas' rather than queries, similar to the following:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim Report As New CrystalReport1
    4. Dim crProp As CRAXDRT.ConnectionProperties
    5.  
    6. Private Sub Form_Load()
    7.  
    8.     Screen.MousePointer = vbHourglass
    9.    
    10.     Set crProp = Report.Database.Tables(1).ConnectionProperties
    11.     crProp.Item("Database Name") = App.Path & "\mydb.mdb"
    12.     crProp.Item("Database Password") = "mypassword"
    13.    
    14.     [color=red]Report.RecordSelectionFormula = "{mytable.myfield}='condition'"[/color]
    15.    
    16.     CRViewer91.ReportSource = Report
    17.     CRViewer91.ViewReport
    18.     Screen.MousePointer = vbDefault
    19.  
    20. End Sub
    So I guess your query would look something like:
    VB Code:
    1. Report.RecordSelectionFormula = "{tCommission.contno} Like '%" & NContNo & "%'"
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

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