Kill a file that is viewed through a listbox

B

bluewatermist

Hello

I'm have difficulty killing a file. Currently on the main userform there is
a command button that once clicked, opens another smaller userform which has
a listbox in it. The listbox displays all text files in a certain C drive
folder. Upon selecting the required file, this smaller userform gets hidden
and unloaded and goes back to the main userform pasting all the information
that was in the selected text file into relevant fields. I have tried using
Kill FileNum or Kill listbox1.value, but without any success. Below is the
coding so far I have used. Hoping you can help me.

Private Sub UserForm_Activate()

Me.ListBox1.Clear

Dim Filename As String
Dim Foldername As String

Foldername = "c:\TPALS Notemaker notes\"
Filename = Dir(Foldername)
Do Until Filename = ""
Me.ListBox1.AddItem (Filename)
Filename = Dir
Loop

End Sub

Private Sub selectcase_Click()

On Error Resume Next
Dim FileNum As Integer
Close
FileNum = FreeFile

Open ListBox1.Value For Input As #FileNum
Input #FileNum, a, b, c etc.......

CWC_Note.typeofcontact.Text = a: typeofentity.OptionButton1.Value = b:
typeofentity.OptionButton2.Value = c: etc.....

Kill FileNum

Close

SelectFile.Hide
Unload SelectFile

End sub
 
D

Dave Peterson

Kill is the VBA command to delete a file. I don't think you want this.

I think you want:

Close FileNum

But if you really wanted to delete a file, you'll want to specify the location:

kill "c:\TPALS Notemaker notes\" & me.listbox1.value

But please make sure you do this against test data--or back up your data first!
 
B

bluewatermist

Hi Dave

Thanks so much it worked :) I had been looking at such complicated ways and
it was so simple.

Much appreciated
Frederic
 

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