Richtextbox mailmerge field formats

Posted by: softcomlimited on 26 August 2019, 10:54 pm EST

    • Post Options:
    • Link

    Posted 26 August 2019, 10:54 pm EST

    Hello,

    I am using AR12 Pro Report Designer, trying to use the RichTextBox for the first time. I am looking for how to apply formatting like “##0.00” and “yyyy-MM-dd” to the [!fields] in the box.

    I can double-click on the box and type in all the surrounding text and the multiple fieldnames, bold, underline etc but I can’t figure out how to format the amount and date fields. Date fields in particular come out with the date and also the time which I don’t want.

    I don’t really want to pre-format the data in my storedproc, I’d like the end-user to choose how they want it to be.

    Regards

    Brian

  • Posted 26 August 2019, 11:45 pm EST

    Hello,

    I have found a not so end-user-friendly method (see below) that needs script in the rpx. But is there a better way ?

    Thanks

    Brian

    Sub Detail_Format
    	me.RichTextBox1.ReplaceField("Balance", Format(rpt.Fields("SharesBal").Value, "$#,##0.00"))
    	me.RichTextBox1.ReplaceField("AsAtDate", Format(rpt.Fields("AsAtDate").Value, "yyyy-MM-dd"))
    End Sub
    
  • Posted 27 August 2019, 9:19 am EST

    Hello Brian,

    Using ReplaceField method is the best possible way to meet your requirement as yet. I am investigating on this further and will get back to you soon, in case there’s a better solution to meet the requirement.

    Regards,

    Esha

  • Posted 27 August 2019, 10:20 am EST

    Ms Dhir,

    Ok, thank you very much.

    Regards

    Brian

  • Posted 29 August 2019, 4:58 am EST

    Hi Brian,

    Just to confirm: As of now, using ReplaceField is the only way to add the formatted fields to the RichTextBox.

    Thanks and Regards.

  • Posted 29 August 2019, 12:06 pm EST

    Ms Dhir,

    Thanks for the update. My method works pretty well.

    Regards

    Brian

    
    Sub Detail_Format
    
    	'fix the formating of the dates and amounts in the RichTextBoxes
    	Dim ctrl AS GrapeCity.ActiveReports.SectionReportModel.ARControl 
    	Dim rtb AS GrapeCity.ActiveReports.SectionReportModel.RichTextBox
    	For Each ctrl In me.Detail.Controls
    		If Typeof ctrl Is GrapeCity.ActiveReports.SectionReportModel.RichTextBox Then
    			rtb = CType(ctrl, GrapeCity.ActiveReports.SectionReportModel.RichTextBox)
    			
    			SetFormat(rtb, "Balance", "$#,##0.00")
    			SetFormat(rtb, "DateOfBirth", "yyyy-MM-dd")
    		End If
    	Next
    		
    End Sub
    
    
    Private Sub SetFormat(rtb AS GrapeCity.ActiveReports.SectionReportModel.RichTextBox, FieldName as String, strFormat as String)
    	'make sure the field actually exists first
    	If rpt.Fields.Contains(FieldName) Then
    		If rpt.Fields(FieldName).Value IS System.DBNull.Value Then
    			'just use blank since we cannot format a NULL
    			rtb.ReplaceField(FieldName, "")
    		Else
    			rtb.ReplaceField(FieldName, Format(rpt.Fields(FieldName).Value, strFormat))
    		End If
    	End If
    End Sub
    
    
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels