Search Text File and Copy String into Field

lucour

Registered User.
Local time
Today, 15:11
Joined
Mar 7, 2001
Messages
60
Hi,

Can anyone tell me how I could search a text file (C:\BankStuff\Validation.txt) for a particular string ("Ticket"), and then copy the next 6 characters to the right of this into a field called txtVal in form Banktransfers?

Thanks!
 
lucour,

You can put this code on the OnClick event of a
command button:


Code:
Dim buf As String
Dim lngPtr As Integer
Dim flgFound As String

flgFound = "No"
Open "C:\BankStuff\Validation.txt" For Input As #1

Line Input #1, buf
While Not EOF(1)
   lngPtr = Instr(1, buf, "Ticket")
   If lngPtr > 0 Then
      Me.txtVal = Mid(buf, lngPtr + 6, 6)
      Close #1
      Exit Sub
   End If
   Line Input #1, buf
   Wend

MsgBox("The line was not found")
Close #1

Wayne
 

Users who are viewing this thread

Back
Top Bottom