Link to home
Start Free TrialLog in
Avatar of qazwsxedc
qazwsxedc

asked on

Cystalreport

i create the cystal report in VB, and a lot of records store inside the table. assume that i have one MDB file content 1 table name "table" and 5 records stored inside this table from number 1 to 5. so how to search through the particular record that i specified and print to cystal report. for example, when i choose the record 3 then how the cystal report gonna to search through ? what's the command or functions using in VB ?

ANYONE KNOW WHAT'S THE BEST SITE FOR CYSTAL REPORT GUIDE ?  
Avatar of percosolator
percosolator

Ok.  Taking your example, I made a form with a textbox, command button and crystal control on it, using the default names that VB supplies.  

Also made an Access database with a simple table in it called "Table" with two fields in it, ID (auto-number) and "Description" (Text). Put five records in.

Code...
-------------------------------------------
Option Explicit

Private Sub Command1_Click()

    Dim i As Integer

    CrystalReport1.SelectionFormula = "{Table.id} = " & Text1.Text
    CrystalReport1.ReportFileName = "C\t1\report1.rpt"
    CrystalReport1.DiscardSavedData = True
    CrystalReport1.WindowState = crptMaximized
   
    i = CrystalReport1.PrintReport
   
    If (i <> 0) Then
   
        MsgBox CrystalReport1.LastErrorString

    End If

End Sub
------------

Tip:  use crystal to create your selection formula and then cut and paste it into VB, pluggin-in your values where needed.

Avatar of qazwsxedc

ASKER

sorry, it doesn't work, error message "Report not found". PLEASE HELP
ASKER CERTIFIED SOLUTION
Avatar of percosolator
percosolator

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this and see if it work

Dim CriteriaStr As String

CriteriaStr = "{Table.id} = " & Text1.Text

frmMain.CrystalReport1.DataFiles(0) = gstrFullDatabaseName
frmMain.CrystalReport1.ReportFileName = gstrReportDirectory & "\MyReport.rpt"
frmMain.CrystalReport1.ReplaceSelectionFormula (CriteriaStr)
frmMain.CrystalReport1.Action = 1

  '======CLEANING THE REPORT SETTING========
      frmMain.CrystalReport1.ReplaceSelectionFormula ("")
      frmMain.CrystalReport1.DataFiles(0) = ""
      frmMain.CrystalReport1.ReportFileName = ""
 '==========================================

Note: Always clean up at the end of setting.