Results 1 to 11 of 11

Thread: sending value in VB to Formula in Crystal Report 8.5

  1. #1

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Unhappy sending value in VB to Formula in Crystal Report 8.5

    holla...

    wrong room perhaps... but pls help... since I know this room will reply faster that other.... and I need this help soon.

    I have a .RPT file which have an empty formula.
    if you ask why empty formula ? coz, I'll send a value to this empty formula from my VB project.

    PS : only 1 formula exist in that .RPT file

    let's say this empty formula name = "period"

    and I have a text box object, name = "txtPeriod"

    what i need to do is to send txtPeriod.Text (in VB) to formula "{period}" in Crystal Report.

    I did as below, but error.....

    VB Code:
    1. Dim CApp As New CRAXDRT.Application
    2.     Dim CReport As CRAXDRT.Report
    3.     Dim myPeriode as String
    4.    
    5.     Screen.MousePointer = vbHourglass
    6.    
    7.     Set CReport = CApp.OpenReport(App.Path & "\myReport.rpt")
    8.    
    9.     CReport.DiscardSavedData
    10.     CReport.PrinterSetup (0)
    11.     myPeriode = "As Of : " & Format(cDate(txtPeriod.Text), "mmm-yyyy")
    12.  
    13.      'error occured at below line
    14.     CReport.FormulaFields(1).Value = myPeriode

    any help ?
    pls...

    thx a lot,
    [-w-]

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    Is CR looking for only the date, or a string?
    Put a breakpoint on the line that formats the date, and see if it is the way that you want it. I think MMMM spells out the month.

  3. #3

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    yup...

    that's the way I need it.

    VB Code:
    1. 'myPeriode should be "As Of : Oct-2004" if month + year of txtPeriod.Text = October 2004..... And I need the string to be sent to a formula at my crystal report (.RPT) file
    2.      myPeriode = "As Of : " & Format(cDate(txtPeriod.Text), "mmm-yyyy")
    3.  
    4.      'error occured at below line... error is "OBJECT REQUIRED"
    5.     CReport.FormulaFields(1).Value = myPeriode

    so ?

    [-w-]

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    I haven't used CR, so I can't help. Are you sure that's how you set the first formula? Could it be (0)? I don't know what else to suggest. You could try posting in the Reporting Forum...

    Just looked, and it looks like you have to assign it to a field, like it appears below.

    CR1.SelectionFormula = "{Cust.Id} =" & MyPeriode

    Maybe not, though. Another attempt:

    CReport.FormulaFields(1).Value = totext(myPeriode)

    this one looks promising
    Last edited by dglienna; Dec 2nd, 2004 at 04:35 AM.

  5. #5

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524
    (0) will return subscript out of range. coz the index start from 1...

    it's okay... I'll wait for another.

    and

    VB Code:
    1. CReport.FormulaFields(1).Value = totext(myPeriode)

    is not working...

    but thx eniwei for ur kind help

    any other help pls ?

    [-w-]

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The Value property is Read Only. Use the Text property to set/change a formula.

    VB Code:
    1. Dim objReport As CRAXDDRT.Report
    2. Const cnstDblQuote As String = """"
    3.  
    4. 'code to open report
    5.  
    6. objReport.FormulaFields(1).Text = cnstDblQuote & "As of Date: " & Format$(Date, "dd-MMM-yyyy") & cnstDblQuote
    7.  
    8. Debug.Print objReport.FormulaFields(1).Text
    9. 'will print "As of Date: 02-Dec-2004"

  7. #7
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    I am using this code in my project with no problems

    Report.FormulaFields.Item(1).Text = "StartDate=" + Chr(34) + glbDateX + Chr(34)

  8. #8
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951
    Bu then, I am using CR9

  9. #9

    Thread Starter
    Fanatic Member Wen Lie's Avatar
    Join Date
    Jul 1999
    Location
    Singapore
    Posts
    524

    Re: sending value in VB to Formula in Crystal Report 8.5


    huehuehue...

    thx a lot to brucevde and pasvorto...

    both are work for me.

    but I still confuse... why .value can't be used ?

    and if I use .text without inserting => """", why does it not workin ?
    (no error, but not workin too)...

    e.g : (yesterday, i've tried below)
    VB Code:
    1. objReport.FormulaFields(1).Text = "AS of : " & Format(Date, "mmm/yyyy") & ""

    when I tried to debug, objReport.FormulaFields(1).Text value is "As of : Dec-2004", but in my Rpt files, no changes at all...

    why is that ?

    I guess this is my last Question to both of u for this case.

    btw, thanks a lot again....
    it works

    [-w-]

  10. #10
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: sending value in VB to Formula in Crystal Report 8.5

    and if I use .text without inserting => """", why does it not workin ?
    (no error, but not workin too)...
    You should be getting an error when you print or preview the report.

    but in my Rpt files, no changes at all...
    This is a runtime change. The changes are dropped when the report object is set to nothing. I have never checked, is there a Save method on the report object.

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: sending value in VB to Formula in Crystal Report 8.5

    You can do this many different way.

    You could create a parameter in CR and use the parameters collection in vb to pass the parameter to CR.

    You could create an ADO recordset with the SQL containing the date filter. Then set the recordset as the .Recordsource for the report.

    Or the parameter could be used in the CR formula. Then pass the parameter to CR.

    ...
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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