ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Kill a file that is viewed through a listbox (https://www.excelbanter.com/excel-programming/427125-kill-file-viewed-through-listbox.html)

bluewatermist

Kill a file that is viewed through a listbox
 
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


Dave Peterson

Kill a file that is viewed through a listbox
 
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!

bluewatermist wrote:

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


--

Dave Peterson

bluewatermist

Kill a file that is viewed through a listbox
 
Hi Dave

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

Much appreciated
Frederic

"Dave Peterson" wrote:

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!

bluewatermist wrote:

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


--

Dave Peterson



All times are GMT +1. The time now is 07:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com