|
-
Dec 2nd, 2004, 03:25 AM
#1
Thread Starter
Fanatic Member
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:
Dim CApp As New CRAXDRT.Application
Dim CReport As CRAXDRT.Report
Dim myPeriode as String
Screen.MousePointer = vbHourglass
Set CReport = CApp.OpenReport(App.Path & "\myReport.rpt")
CReport.DiscardSavedData
CReport.PrinterSetup (0)
myPeriode = "As Of : " & Format(cDate(txtPeriod.Text), "mmm-yyyy")
'error occured at below line
CReport.FormulaFields(1).Value = myPeriode
any help ?
pls...
thx a lot,
[-w-]
-
Dec 2nd, 2004, 03:47 AM
#2
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.
-
Dec 2nd, 2004, 04:18 AM
#3
Thread Starter
Fanatic Member
yup...
that's the way I need it.
VB Code:
'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
myPeriode = "As Of : " & Format(cDate(txtPeriod.Text), "mmm-yyyy")
'error occured at below line... error is "OBJECT REQUIRED"
CReport.FormulaFields(1).Value = myPeriode
so ?
[-w-]
-
Dec 2nd, 2004, 04:24 AM
#4
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.
-
Dec 2nd, 2004, 04:54 AM
#5
Thread Starter
Fanatic Member
(0) will return subscript out of range. coz the index start from 1...
it's okay... I'll wait for another.
and
VB Code:
CReport.FormulaFields(1).Value = totext(myPeriode)
is not working...
but thx eniwei for ur kind help 
any other help pls ?
[-w-]
-
Dec 2nd, 2004, 03:20 PM
#6
The Value property is Read Only. Use the Text property to set/change a formula.
VB Code:
Dim objReport As CRAXDDRT.Report
Const cnstDblQuote As String = """"
'code to open report
objReport.FormulaFields(1).Text = cnstDblQuote & "As of Date: " & Format$(Date, "dd-MMM-yyyy") & cnstDblQuote
Debug.Print objReport.FormulaFields(1).Text
'will print "As of Date: 02-Dec-2004"
-
Dec 2nd, 2004, 03:33 PM
#7
PowerPoster
I am using this code in my project with no problems
Report.FormulaFields.Item(1).Text = "StartDate=" + Chr(34) + glbDateX + Chr(34)
-
Dec 2nd, 2004, 03:34 PM
#8
PowerPoster
-
Dec 3rd, 2004, 05:20 AM
#9
Thread Starter
Fanatic Member
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:
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-]
-
Dec 3rd, 2004, 11:23 AM
#10
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.
-
Dec 3rd, 2004, 12:19 PM
#11
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|