Solved

(Drive1.Drive) CD IN ??

Posted on 2001-08-29
4
177 Views
Last Modified: 2011-08-18
Hi i am using Dir1.Path = Drive1.Drive to pas the selcted drive to a dir1 box

the problem is when i have no CD in mu CDrom bay and this is selected my prgram falls over ??

SILKI :o)
0
Comment
Question by:silki
4 Comments
 
LVL 20

Expert Comment

by:hes
ID: 6436904
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 50 total points
ID: 6436944
why not do something like this:

On Error GoTo NMEDIA
Dir1.Path = Drive1.Drive
Exit Sub
NMEDIA:
MsgBox "No Media in Drive!"
Drive1.Drive = Left(Dir1.Path, 2)
0
 
LVL 1

Expert Comment

by:atp_expert
ID: 6440401
Option Explicit
Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long
Private Sub Command1_Click()
 Dir1.Path = IIf(SetCurrentDirectory(Left(Drive1.Drive, 2) = 0), Dir1.Path, Drive1.Drive)
End Sub

The setcurrentdirectory (api) will fail when, the directory or drive doesn't exits, so when u dont have a CD in ur drive, this api will fail, hence u can assign the previous drive.
0
 

Author Comment

by:silki
ID: 6440476
Simple yet effective !!

Thanx

SILKI
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel - Save a copy of work book 13 85
How to compare ms sql hashbytes results within vb6 5 77
Add and format columns in vb6 7 59
fso.FolderExists("\\server\HiddenFolder$") 4 70
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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

825 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