-----Original Message-----
On Sun, 19 Dec 2004 12:43:07 -0800, "Mat"
So lets start from the Beginning:
My sample needs:
a reference to MicroSoft DAO 3.x in Tools----References
it creates now a new table ( if this table is not existing)
it takes the Fields: theEmail, LastSend,theSubject
three thinks struck my mind:
the file in PathName has to exist
the dates have to be in Order to get the last entry
the logfile gets read everytime from the beginning
paste this into a new Module
Option Compare Database
Option Explicit
Sub WriteTheLogIntoMyTable()
Dim Ary() As String
Dim stTmp As String
Dim rs As DAO.Recordset
Dim I As Long
Dim db As DAO.Database
Dim PathName As String
Dim TableName As String
Dim stTemp As String
Set db = CurrentDb
PathName = "C:\emailTest.txt"
'this is the location and name of your logfile
TableName = "MyTable"
'this is the Table I need
CheckTable db, TableName
'if this table is not existing, it gets created
stTemp = "SELECT theEmail, LastSend,theSubject " _
& " FROM " & TableName
'this is the SQL string to choose the fields from the table
Set rs = db.OpenRecordset(stTemp, , dbOpenDynaset)
'this is openening a recordset for finding
Open PathName For Input As #1
'not I open the logFile
While Not EOF(1)
' read the file till EndOfFile
Line Input #1, stTmp
'read a single line (dump the end of line marker)
Ary = Split(stTmp, " ")
'split the readLine on blank
rs.findfirst "theEmail='" & Ary(UBound(Ary)) & "'"
'find the first match of the email
' if you have a few 1000 emails this will be the bootleneck
If rs.noMatch Then
'if it is not in the table, then add it
rs.AddNew
rs!theEmail = Ary(UBound(Ary))
'it is the end of the read line
Else
'it was found
rs.edit
End If
rs!lastSend = Ary(1)
' change the date
stTemp = ""
For I = 6 To UBound(Ary) - 2
'add the subject, which can have a lot of blanks
'therefor add everything between the date and the TO
stTemp = stTemp & Ary(I)
Next I
rs!theSubject = stTemp
rs.Update
'write the field to disk
Wend
Close #1
'close the file, if you miss this you can't open it again
rs.Close
'close the recordset
Set rs = Nothing
Set db = Nothing
'set all object you used to nothing
End Sub
Sub CheckTable(db As DAO.Database, TableName As String)
Dim SQL As String
Dim tbl As DAO.TableDef
On Error Resume Next
Set tbl = db.TableDefs("MyTable")
If Err.Number <> 0 Then
SQL = "CREATE TABLE " & TableName _
& " (theEmail CHAR(255) NOT NULL" _
& ", LastSend DATE" _
& ", theSubject CHAR(255))"
CurrentDb.Execute SQL
End If
db.TableDefs.Refresh
Set tbl = Nothing
End Sub
If you expect an answer to a personal mail, add the