?
Solved

Deleting a file using if Keycode... HLP PLS

Posted on 2003-03-02
8
Medium Priority
?
148 Views
Last Modified: 2010-05-01
Hello,

Im want to del a file using the DEL key.
this is the code that won't work

Private Sub File1_Click()
    SelectedFile = File1.Path & "\" & File1.FileName
    Image1.Picture = LoadPicture(SelectedFile)
 If KeyCode = vbKeyDelete Then GoTo Kill
Exit Sub
Kill:
    MsgBox "Are you sure?"
    Kill File1.Path & "\" & File1.FileName
    File1.Refresh
End Sub

What is wrong ?!?

ThnX, TJ2002
0
Comment
Question by:TJ2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 3

Expert Comment

by:DeAn
ID: 8053767
use the keyup instead of click

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)

Integer, X As Single, Y As Single)
   SelectedFile = File1.Path & "\" & File1.FileName
   Image1.Picture = LoadPicture(SelectedFile)
If KeyCode = vbKeyDelete Then GoTo Kill
Exit Sub
Kill:
   MsgBox "Are you sure?"
   Kill File1.Path & "\" & File1.FileName
   File1.Refresh

End Sub
0
 

Author Comment

by:TJ2002
ID: 8053789
thnx,

but the loadPicture wont work any more....
is it also posible to use it whit multi files??

TJ
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8053833
I had some extra code in there from pasting:

  Integer, X As Single, Y As Single)

(I'm sure you got rid of that)

is the file a valid picture file you're selecting from the File1 list?

for multiple files selected you will have to loop through each selected item and kill them.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:TJ2002
ID: 8053854
Yep.. i removed the Integer, X As Singl....

im sure that the image is valid... it works whit te 'OLD' code...

PS; the code is for a FileListBox!!, i for got to say that;p

TJ2002
0
 
LVL 3

Accepted Solution

by:
DeAn earned 80 total points
ID: 8053859
you can separate the code like this.

Private Sub File1_Click()
  Dim SelectedFile As String
  SelectedFile = File1.Path & "\" & File1.FileName
  Image1.Picture = LoadPicture(SelectedFile)
End Sub

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyDelete Then GoTo Kill
  Exit Sub
Kill:
  'MsgBox File1.Path & "\" & File1.FileName
  Kill File1.Path & "\" & File1.FileName
  File1.Refresh
End Sub
0
 

Author Comment

by:TJ2002
ID: 8053871
THANX....

It's working..

GreetZ
TJ2002
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8053876
this should delete all selected

Private Sub File1_Click()
  Dim SelectedFile As String
  SelectedFile = File1.Path & "\" & File1.FileName
  Image1.Picture = LoadPicture(SelectedFile)
End Sub

Private Sub File1_KeyUp(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyDelete Then GoTo Kill
  Exit Sub
Kill:
  Dim i As Integer
  For i = 0 To File1.ListCount - 1
    If File1.Selected(i) = True Then
    Kill File1.Path & "\" & File1.List(i)
    End If
  Next i
  File1.Refresh
End Sub
0
 
LVL 3

Expert Comment

by:DeAn
ID: 8053881
yw, thx for the points
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question