Link to home
Start Free TrialLog in
Avatar of amkhara
amkhara

asked on

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)
Avatar of traygreen
traygreen

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 ;)
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

Avatar of amkhara

ASKER

Sorry, sorry, sorry... I forgot Exit Sub, but I have it in my code... Anyway, it doesn't work.
Avatar of amkhara

ASKER

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!
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.

Avatar of amkhara

ASKER

 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! :)
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.


Avatar of amkhara

ASKER

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
¿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.
ASKER CERTIFIED SOLUTION
Avatar of fguerreiro_inix
fguerreiro_inix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amkhara

ASKER

 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...