Maybe Option #4??
Table named "Import"
Fields "SSN" & "Code"
1) Uses DAO
In the IDE (VBA Editor), there must be a reference set to "Microsoft DAO3.6 Object Library"
2) This assumes there is NO header line. (as per example data)
3) Change the line in BLUE to the path and name of your text file.
In a standard module, paste in the following code: (Name the module "modImportCode")
Code:
Public Sub TextImport()
Dim i As Integer
Dim RF As Integer 'RF read file
Dim FileName As String
Dim strInput As String
Dim sSSN As String
Dim sCode As String
Dim sSQL As String
FileName = "C:\AccMDB\SSNImport.txt"
RF = FreeFile
Open FileName For Input As #RF
' since the example had an even number of lines, check to see if the text file has an even number of lines
Do While Not EOF(RF)
Line Input #RF, strInput
i = i + 1
Loop
Close #RF
If i Mod 2 <> 0 Then
MsgBox "Odd number of lines in text file" & vbNewLine & vbNewLine & "Must be an even number of lines" & vbNewLine & vbNewLine & "Exiting!!"
Exit Sub
End If
' good to go
Open FileName For Input As #RF
Do While Not EOF(RF)
sSSN = Empty
sCode = Empty
strInput = Empty
Line Input #RF, strInput
sSSN = Left(Trim(strInput), 11)
Line Input #RF, strInput
sCode = Right(Trim(strInput), 1)
sSQL = "INSERT INTO Import(SSN, Code)"
sSQL = sSQL & " VALUES ('" & sSSN & "', '" & sCode & "');"
CurrentDb.Execute sSQL, dbFailOnError
' Debug.Print sSQL
Loop
Close #RF
MsgBox "Done"
End Sub
Execute the code. (While in the IDE, press the F5 key)