[RESOLVED] how to create the data report from text file?
Hi,
I already know how to import text file to datagrid,may i how to create the data report from the text file??
my text file content:
2310047019902,50,18/12/2013,08:24
2310057019909,80,18/12/2013,08:24
2310073019907,2000,18/12/2013,08:24
2310048019901,50000,18/12/2013,08:25
2310067019906,2,18/12/2013,08:25
my code:
Module
Code:
Option Explicit
Public cn As New ADODB.Connection
Public rs As New ADODB.Recordset
Public Sub Connect()
Dim Path1 As String
Path1 = App.Path & "C:\aaa\test.txt"
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\aaa\;Extended Properties=""text;HDR=No;FMT=Delimited"""
With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = "Select * From test.txt"
.Open
End With
End Sub
Public Sub RSCheck()
If rs.State = 1 Then rs.Close
End Sub
command button
Code:
Private Sub Command1_Click()
Dim SQL As String
If rs Is Nothing Then
Set rs = New ADODB.Recordset
End If
RSCheck
SQL = "Select * From test.txt"
rs.Open SQL, cn, adOpenStatic, adLockReadOnly
Set DataReport1.DataSource = rs
DataReport1.Show
End Sub
Private Sub Form_Load()
Connect
If Not rs.BOF And Not rs.EOF Then
rs.Sort = "F1 ASC"
rs.Requery
Set DataGrid1.DataSource = rs
End If
End Sub
You should use the DataReport Designer to make your report.
However DataReport isn't a good tool, very obsolete and limited.
I suggest to use Cristal Report 4.6 (it come with VS6/VB6) that's very very good.
You will find CR4.6 on your CDs (depend of your version)
thank you for your suggestion, but to create the report from database (MS access) is no problem, if from text file i don't know how? can you show me the simple example how to create report (data source: text file) not a .mdb
You can do this using a DataEnvironment as a DataSource or you can do it using just an ADO Recordset. In either case you will want to use the Jet 4.0 OLEDB Provider, and you'll want a Schema.ini file to provide information about the structure of your text data file.
Here's a quick and dirty demo:
The truth is that VB6 DataReports were meant to replace Crystal Reports, which was included only to aid in porting old VB5 programs to VB6. Of course the DataReport was meant to become more powerful in future versions of VB, but then The Great Destruction (.Net) came along and nipped progress in the bud.
thank you so much for your demo dilettante, it really help me a lot, but i not familiar using the schema.ini file. if i want to use dataenvironment as a data source like you mention, how to do this? any idea?
*sorry my english not so well*
Re: [RESOLVED] how to create the data report from text file?
The only thing in the resources was an application manifest. That is completely optional, but VB6 programmers are supposed to know about these things these days.
You can remove that resource entirely. It has nothing to do with making a DataReport work.