Dim FOP As String
Dim RS As DAO.Database
Set RS = CurrentDb.OpenRecordset("tblMIR")
If IsNull(txtMIRPath) = True Then
MsgBox ("Check MIR file path")
Exit Sub
End If
MIR = [Forms]![form1]![txtMIRPath] & ".MIR"
DoCmd.Hourglass True
Open MIR For Input As #1 'Open specified file
Do While Not EOF(1)
Line Input #1, TextLine
If Left(TextLine, 2) = "T5" Then
IATACode = Trim(Mid(TextLine, 5, 4)) 'Reads the IATA Code
RS.AddNew
RS![IATACode] = IATACode
Jdraw, the link does not show anything related to importing to a table. Namliam, hard time kick starting
Curious to see your codeDone ! Managed to add data of the text file to the table.
How can i automate this ? like read all files with extention .txt in a folder and move processed file into C:\Processed with current date
Dim src As String
Dim dst As String
src = Dir("C:\MIR\*.MIR")
dst = "C:\MIR\Processed"
Set RS = CurrentDb.OpenRecordset("tblMIR")
Do While src <> ""
DoCmd.Hourglass True
Open src For Input As #1 'Open specified file
'Do While Not EOF(1)
Line Input #1, TextLine
If Left(TextLine, 2) = "T5" Then
..................Code follows..................
DoCmd.Hourglass False
RS.Update ' update table tblMIR
RS.Close ' Close the table
Set RS = Nothing ' Clear RS
Close #1 ' Close file
dim srcfolder as string
Dim srcfile As String
Dim dstfolder As String
srcfolder = "C:\MIR\"
dstfolder = "C:\MIR\Processed\"
srcfile = Dir(srcFolder & "*.MIR")
Set RS = CurrentDb.OpenRecordset("tblMIR")
Do While src <> ""
DoCmd.Hourglass True
Open srcFolder & src For Input As #1 'Open specified file
Do While Not EOF(1)
Line Input #1, TextLine
If Left(TextLine, 2) = "T5" Then
..................Code follows..................
RS.Update ' update table tblMIR
loop
Close #1 ' Close file
name srcfolder & srcfile as dstfolder & srcfile
srcfile = dir 'get next file
loop
DoCmd.Hourglass False
RS.Close ' Close the table
Set RS = Nothing ' Clear RS
Do While src <> ""
Do While srcfile <> ""
Open srcFolder & src For Input As #1
Open SrcFolder & srcfile For Input As #1
txtMIRActivity.Value = srcfile
If Left(TextLine, 3) = Trim("A02") Then 'First A02(PAX) line
pax = Trim(Mid(TextLine, 4, 30))
TKT = ALC & Trim(Mid(TextLine, 49, 10))
Passenger = TKT & " " & pax
Line Input #1, TextLine
Line Input #1, TextLine
Else
MsgBox ("Failed to find passengers in file " & "'" & SrcFolder & srcfile & "'" & vbNewLine & _
"Try moving" & "'" & SrcFolder & srcfile & "'" & " to another folder and re-run the Parser again.")
Close #1
Exit Sub
End if
txtMIRActivity.Value = srcfile