Hi,
The code below is uses a command button to save the current list values to a file and loads it from the file at Form Load.
Private Sub Form_Load()
On Error GoTo errHandler
intFile = FreeFile
Open "C:\test.txt" For Input As intFile
Input #intFile, str
Close #intFile
lastPos = 1
currPos = 1
If InStr(1, str, ",", vbBinaryCompare) <> 0 Then
Do While InStr(lastPos, str, ",", vbBinaryCompare) <> 0
currPos = InStr(lastPos, str, ",", vbBinaryCompare)
List1.AddItem Mid(str, lastPos, currPos - lastPos)
lastPos = currPos + 1
Loop
List1.AddItem Mid(str, lastPos, Len(str) - (lastPos - 1))
Else
List1.AddItem str
End If
Form_Exit:
Exit Sub
errHandler:
Select Case Err.Number
Case 53
Resume Form_Exit
Case Else
MsgBox "Unexpected Error" & vbCrLf & Err.Number & vbCrLf & Err.Description, , "ERROR"
End Select
End Sub
Private Sub SaveList_Click()
str = ""
For i = 0 To List1.ListCount - 1
If str = "" Then
str = List1.List(i)
Else
str = str & "," & List1.List(i)
End If
Next i
intFile = FreeFile
Open "C:\test.txt" For Output As #intFile
Write #intFile, str
Close #intFile
MsgBox "Values saved to file C:\test.txt"
End Sub
Hope it helps. Let me know what happens.
With regards,
PGK
Hope it helps. Let me know what happens.
With regards,
PGK