Change:
rpt.DataDefinition.RecordSelectionFormula = "Select * employee where empposition='"& "Programmer" & "'"'
to
rpt.DataDefinition.RecordSelectionFormula = "{employee.empposition} = 'Programmer' "
The selection formula is like the where clause.
This is how I export report data setting the record selection formula at runtime:
Code:
Public Sub CreateImportFile
Dim crxApp As New CRAXDRT.Application
Dim crxRpt As CRAXDRT.Report
'Open report
Set crxRpt = crxApp.OpenReport(App.Path & "\report.rpt")
crxRpt.RecordSelectionFormula = createSelectionFormula(parameterString)
'Set export parameters
With crxRpt
.ExportOptions.DestinationType = crEDTDiskFile
.ExportOptions.FormatType = crEFTCommaSeparatedValues
.ExportOptions.DiskFileName = App.Path & "\rpt.txt"
End With
'Export report
crxRpt.Export False
'Destroy objects
Set crxApp = Nothing
Set crxRpt = Nothing
Exit Sub
End Sub
Private Function createSelectionFormula(param As String) As String
Dim sFormula As String
sFormula = "{employee.empposition} = '" & param & "'"
createSelectionFormula = sFormula
End Function