Solved

Run-time error 68: Device unavailable

Posted on 1998-11-12
11
1,695 Views
Last Modified: 2012-06-22
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
Comment
Question by:amkhara
11 Comments
 
LVL 3

Expert Comment

by:traygreen
ID: 1444482
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
 
LVL 3

Expert Comment

by:vikiing
ID: 1444483
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
 

Author Comment

by:amkhara
ID: 1444484
Sorry, sorry, sorry... I forgot Exit Sub, but I have it in my code... Anyway, it doesn't work.
0
 

Author Comment

by:amkhara
ID: 1444485
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
 
LVL 3

Expert Comment

by:vikiing
ID: 1444486
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:amkhara
ID: 1444487
 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
 
LVL 3

Expert Comment

by:vikiing
ID: 1444488
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
 

Author Comment

by:amkhara
ID: 1444489
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
 
LVL 3

Expert Comment

by:vikiing
ID: 1444490
¿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
 
LVL 3

Accepted Solution

by:
fguerreiro_inix earned 200 total points
ID: 1444491
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
 

Author Comment

by:amkhara
ID: 1444492
 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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now