Hi,
I am a newbie to VB and Crystal Report and would appreciate any assistance. What I am trying to do is to read a text file containing some data and to display the data in Crystal Report using unbounded fields.
I have managed to setup the DSN-less connection but having problems when viewing the report. I keep getting "Unable to access first record". Can anyone help?
Below is the code:
'Declare database objects
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim objErr As ADODB.Error
'Establish a database connection using NT Authentication
objConn.Open "Driver={Microsoft Text Driver (*.txt;.csv)};" & _
"Dbq=c:\reports; Extensions=asc,csv,tab,txt;"
'Check the state of the connection to ensure we are connected
If objConn.State = adStateOpen Then
'Open a recordset
objRS.Open "SELECT * FROM file.txt", objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
m_Report.Database.Tables.Add "", , objRS, , "p2smon.dll"
m_Report.Database.SetDataSource objRS, 3
With m_Report
.Instance.SetUnboundFieldSource "{ado.field1}"
.PartNumber.SetUnboundFieldSource "{ado.field2}"
End With
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport
Else
'Display all errors
For Each objErr In objConn.Errors
Debug.Print objErr.Description
Next
End If
the contents of file.txt is
field1,field2
ab,cd
ef,gh
ij,kl
Thanks in advance
I am a newbie to VB and Crystal Report and would appreciate any assistance. What I am trying to do is to read a text file containing some data and to display the data in Crystal Report using unbounded fields.
I have managed to setup the DSN-less connection but having problems when viewing the report. I keep getting "Unable to access first record". Can anyone help?
Below is the code:
'Declare database objects
Dim objConn As New ADODB.Connection
Dim objRS As New ADODB.Recordset
Dim objErr As ADODB.Error
'Establish a database connection using NT Authentication
objConn.Open "Driver={Microsoft Text Driver (*.txt;.csv)};" & _
"Dbq=c:\reports; Extensions=asc,csv,tab,txt;"
'Check the state of the connection to ensure we are connected
If objConn.State = adStateOpen Then
'Open a recordset
objRS.Open "SELECT * FROM file.txt", objConn, adOpenForwardOnly, adLockReadOnly, adCmdText
m_Report.Database.Tables.Add "", , objRS, , "p2smon.dll"
m_Report.Database.SetDataSource objRS, 3
With m_Report
.Instance.SetUnboundFieldSource "{ado.field1}"
.PartNumber.SetUnboundFieldSource "{ado.field2}"
End With
CRViewer1.ReportSource = m_Report
CRViewer1.ViewReport
Else
'Display all errors
For Each objErr In objConn.Errors
Debug.Print objErr.Description
Next
End If
the contents of file.txt is
field1,field2
ab,cd
ef,gh
ij,kl
Thanks in advance