Not too certain what is in your *.txt file.
But would be better to append each line to a List box.
Just off the top of my head . . .
'++++++++++++++++++++++++++++++++++++++++++++
'Best place this in a module, then you can reuse in other projects, other stick it in your form code
Public Function ImportFileDetails(ImportFile As String) As Boolean
Dim ImportText As String
On Error GoTo ImportFileDetails_Error
'Check if file is present
If Dir(ImportFile) = "" Then
'If not raise error
Err.Raise 4999
End If
'Open file to read
Open ImportFile For Input As #1
'Loop through File
Do While Not EOF(1)
'Store contents of line in Variable
Input #1, ImportText
'Append contents to List Box on form
ListBoxNameHere.AddItem ImportText
Loop
'Close File
Close #1
ImportFileDetails_Exit:
ImportFileDetails = True
Exit Function
ImportFileDetails_Error:
Select Case Err.Number
Case 4999
MsgBox "Cannot locate file " & ImportFile, vbCritical + vbOKOnly, "File Load Error"
Case Else
MsgBox "Error Number: " & Err.Number & " - " & Err.Description, vbCritical + vbOKOnly, "File Load Error"
End Select
End Function
' +++++++++++++++++++++++++++++++++++++++++++++++++++
Private Sub CommandButtonNameHere_Click()
'Update text details on screen
If ImportFileDetails("Dir + FileName.txt") Then
MsgBox "Update Complete", vbOKOnly, "File Load"
End If
End Sub