• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2219
  • Last Modified:

Run-time error 68: Device unavailable

I have a problem that's is driving me fool... This is my code:
On Error GoTo TratarError

If pedir_copia then
  frmDirectorio.fraCopia.Visible = True
  frmDirectorio.txtCopia.Text = "A:"
  frmDirectorio.drvCopia.Drive = "A:"
  frmDirectorio.dirCopia.Path = "A:"
End If

TratarError:
  If (Err.Number=68) Then
    MsgBox "Error", 16, "ERROR"
  End If

Now, the problem... If I have a diskette in the A drive, all goes on right. But if I don't have a diskette inserted, I got the "Run-time error 68". I've tried to treat the error in this procedure, and in the event that ".Drive" generates, but I got nothing.
  Someone can help me, please? (sorry for my English)
0
amkhara
Asked:
amkhara
1 Solution
 
traygreenCommented:
The error code will always execute because there is nothing to tell it not to.
If the code is in a function put "exit sub" between the "end if" and the "TratarError:"
If in a function put "exit function" between the "end if" and the "TratarError:"

BTW: your English is better than quite a few anglos I know ;)
0
 
vikiingCommented:
En lo posible, la rutina de tratamiento de errores debe hacer lo minimo indispensable. Si detectas el error 68, puedes bifurcar (via RESUME) a una seccion que trate ese error:

On Error Goto TratarError
bla
bla
bla

End

DeviceUnav:
   MsgBox("bla bla bla")
   Exit Sub

TratarError:
   If Err=68 then Resume DeviceUnav
   On error goto   'Frente a otro error imprevisto, dejar que VB
                   'cancele el programa (o hacer una rutina de
                   'tratamiento de errores imprevistos).

End Sub

Espero que te sirva

0
 
amkharaAuthor Commented:
Sorry, sorry, sorry... I forgot Exit Sub, but I have it in my code... Anyway, it doesn't work.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
amkharaAuthor Commented:
Another note: The error code never executes... The program crashes... Maybe, I don't explain it clear enough.
  This is my first question :). Ah! I can't answer during the weekend, so if somebody answers my question then, I'll see the emails on Monday... work!
  Thnx!
0
 
vikiingCommented:
Tu último comentario dice "The program crashes". ¿Cuál es exactamente el error que muestra cuando el programa se muere? (obviamente debe ser otra cosa, y no el error 68, ya que lo estás interceptando en la sección de errores).

Por favor, contá un poco más el lunes.

0
 
amkharaAuthor Commented:
 The program crashes means that... the program crashes giving error 68. So I'm so confused... I've gone on probing my code and I've noticed that program crashes at more points that has "On Error" sentences... Might be a bug?? It seems not to execute error treatment...
  Quiere decir eso... que el programa aborta dando el error 68. Por eso estoy confundida... He seguido probando mi programa y me he dado cuenta de que el programa aborta en mas sitios que tiene sentencias "On Error"... Podria ser un bug?? Parece que no ejecuta el tratamiento de error...
  Have a good weekend! :)
0
 
vikiingCommented:
You can test your error handling routine whithout need of accessing diskette. Comment out the instruction regarding A: access, and replace it with "Error 68" instruction. That will force error 68 to be generated.

One thing I've noted: your original code does NOT have a RESUME. If (any) error is detected for second time, as RESUME wasn't executed at all, as "pending" flag for that error still remains active, VB takes control and executes its normal procedure, this is, forcing the program to explode.


0
 
amkharaAuthor Commented:
You're right, but I've inserted Resume instruction in my code, and goes on crashing... In fact, none of the On Error instructions all over the code goes on right... and all of them have their Resume instruction
Tienes razon, pero he insertado la instruccion Resume y sigue cascando... En realidad, ninguna de las instrucciones On Error del codigo parece que vaya bien... y todas tienen su instruccion Resume
0
 
vikiingCommented:
¿Could you post, please, the entire error routine you've written?

PS: I'll keep on writting plain English, Amkhara; don't worry if you don't add the Spanish translation.
0
 
fguerreiro_inixCommented:
I've tested the folowing code and it works well.

--------------------------
On Error GoTo ErrorRoutine
File1.Path = "a:"

Exit Sub

ErrorRoutine:
If Err.Number = 68 Then
    MsgBox Err.Number
    Resume Next
End If
-------------------------

Your code probably is well done but you are using
in the Menu Tools\Options\General section Error Trapping
the Break on All Errors option. With this option checked
even if you have error handling routines in your code the
execution breaks if an error ocurs.

Hope this helps
Regards


0
 
amkharaAuthor Commented:
 Thanks all of you for your help... You are right, fguerreiro_inix, I hadn't watched the options... now I've changed them and works fine...
  Gracias vikiing por tu amabilidad...

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now