Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Links removed when connecting with the RDC (Automatic SetLocation)

Hello,

We have a VB6 application that is using the Crystal Report 11 RDC to display reports. When we are connecting the report to the database, one of the SQL links is removed because a field contained in this link is removed from its table. This behaviour gives us problem because the data returned is not good anymore. We would have expected the report to leave the SQL intact and give an error instead.

Is there a way to workaround this behavior.

Thank you.

Former Member
replied

OK. So from your description, you have essentially the same issue in the designer and at runtime. The "match for the missing fields" is the field mapping dialog. Now, the designer is nice enough to prompt you with a request to tell it what you want to do with the missing field. Runtime is not. E.G.; you designed the report with a particular field and so the report expects that field to be there. if it's not, it has no idea what to do.

You can force the field mapping dialog at runtime, but you will have to code for it as follows:

**

' Purpose: Demonstrate how to manipulate Field Mapping

'

' Field mapping allows the user to change the name of

' a database field that a report field points to if

' that field no longer exists or has been renamed in

' the data source.

'

' In this sample, the Report_FieldMapping event in the

' code for CrystalReport1 is used to programmatically

' change the mapping of the report fields to a different

' database field.

'

Option Explicit

Dim crApplication As New CRAXDRT.Application

Dim WithEvents m_Report As CRAXDRT.Report

Attribute m_Report.VB_VarHelpID = -1

Dim ReportDB As Database

Dim MappingData As CRAXDRT.FieldMappingData

Dim dbMappingData As CRAXDRT.FieldMappingData

Private Sub CRViewer11_CloseButtonClicked(UseDefault As Boolean)

End Sub

' *

' Load the Report in the viewer and enable fieldmapping

'

Private Sub Form_Load()

Set m_Report = crApplication.OpenReport(App.Path & "\FieldMapping.rpt";)

Set ReportDB = m_Report.Database

' Explanation of FieldMappingType:

' 0 - crAutoFieldMapping - Remove all report fields which do not have the same

' name in the new database

' 1 - crPromptFieldMapping - Display a dialog box to get the user to manually

' map the fields

' 2 - crEventFieldMapping - Cause the Report_FieldMapping event to be triggered

'

m_Report.FieldMappingType = crEventFieldMapping

' Verifying the database or using SetLocation will trigger the Field Mapping event

'ReportDB.Verify

' Display our report in the viewer

CRViewer11.ReportSource = m_Report

CRViewer11.ViewReport

End Sub

' **

Private Sub cmdAbout_Click()

frmAbout.Show vbModal

End Sub

' **

Private Sub cmdExit_Click()

Unload Me

End Sub

Private Sub m_Report_FieldMapping(reportFieldArray As Variant, ByVal databaseFieldArray As Variant, UseDefault As Boolean)

' Setting useDefault to True will cancel all fieldmapping

UseDefault = False

' Get the first field in the report ("LastName")

Set MappingData = reportFieldArray(0)

' Setting MappingToFieldIndex to -1 will remove this field from the report

' Set the db field to point to the second database field in the report,

' which happens to be "Last Name"

MappingData.MappingToFieldIndex = 2

MsgBox "Mapped '" & MappingData.FieldName & "' ", vbInformation

' Get the first field in the report ("Total Salary")

Set MappingData = reportFieldArray(3)

Set dbMappingData = databaseFieldArray(12)

' Set the db field to point to the ninth database field in the report,

' which corresponds to "Salary"

MappingData.MappingToFieldIndex = 12

MsgBox "Mapped '" & dbMappingData.FieldName & "' ", vbInformation

End Sub

Ludek

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question