Read a text file into a form

A

Arnie

hi folks not very good at programming so if anyone could help.

i need to read a text file which can be opened in notepad but the extention
is (.ABC and .DEF) firstly how do i get Access to recognise theese extentions.

secondly how do i read the file into the form ie in the file i would have

IPAddress=???????
DefaultGateway=???????
PreferedDNS=??????

i only need to read after the = then move to the next item

thanks in advance
 
D

Douglas J. Steele

It's not clear to me why you need to get Notepad involved.

It sounds as though all you need is to read the file programmatically.

Dim intFile As Integer
Dim intEqualSign As Integer
Dim strFile As String
Dim strBuffer As String
Dim strBefore As String
Dim strAfter As String
Dim strIPAddress As String
Dim strDefaultGateway As String
Dim strPreferredDNS As String

strFile = "C:\Folder\File.abc"
intFile = FreeFile()
Open strFile For Input As #intFile
Do While Not EOF(intFile)
Line Input #intFile, strBuffer
intEqualSign = InStr(strBuffer, "=")
If intEqualSign > 0 Then
strBefore = Left$(strBuffer, intEqualSign - 1)
strAfter = Mid$(strBuffer, intEqualSign + 1)
Select Case strBefore
Case "DefaultGateway"
strDefaultGateway = strAfter
Case "IPAddress"
strIPAddress = strAfter
Case "PreferedDNS"
strPreferedDNS = strAfter
End Select
End If
Loop
Close #intFile
 
A

Arnie

sorry forget notepad its what i use to view the file

anyway thanks for that i can see it reading through the file no problem its
just how do i get the data into a field in a table or form?
 
D

Douglas J. Steele

Either open a recordset and set the field values according, or else write an
INSERT INTO SQL statement and execute it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top