0 Replies - 980 Views - Last Post: 27 December 2013 - 10:10 PM Rate Topic: -----

#1 hwkong1688  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 30-September 11

how to create the data report from text file?

Posted 27 December 2013 - 10:10 PM

Hi,
I already know how to import text file to datagrid,may i how to create the data report from the text file??
now my data report is empty (error: data field '(empty)' not found)

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
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
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



Is This A Good Question/Topic? 0
  • +

Page 1 of 1