File remains open

ino_mart

Registered User.
Local time
Today, 08:13
Joined
Oct 7, 2009
Messages
78
All

I have a combobox which shows some files from a specific folder. Furthermore I have a button "cmdLoadPreset" to open the file currently chosen in the combobox. The code inside "cmdLoadPreset" calls another sub LoadPreset with the filename as parameter. This code does work as the content of the file is shown in Me.txtDetail.

Code:
Private Sub LoadPreset(Optional strFile As String)
Dim intFileNum As Integer
Dim strData As Variant
intFileNum = FreeFile
 
Open strFile For Binary Access Read As intFileNum
Me.txtDetail=""
Do While Not EOF(intFileNum)
    Get intFileNum, , strData
    Me.txtDetail = Me.txtDetail & strData
Loop
Close #intFileNum
End Sub

Furthermore I have a seperate button which deletes the file which is chosen in the combobox. I use next statement in that specific sub.
Code:
Kill strPresetsPath & "\" & Me.cboPresets.Value & ".avdp"

The Kill-command only works when I did not open the file yet. If I first load the file and I try to delete it afterwards, I get "Run-time error 55: File already open" although the LoadPreset-sub does have the line "Close #intFileNum"

What's going wrong?

Regards
Ino
 
If you're only opening the file as read only, a last ditch solution would be to copy the file to the temp directory and open the copied file - leaving the original free to be deleted.

In other programming languages, when showing previews of images for example, that's often a simple solution to just the same sort of problem.
 
You'd get this scenario if your close doesn't execute because of an error, and your error handling is disabled.

Did you debug and check that the close statement does run?
 

Users who are viewing this thread

Back
Top Bottom