[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

(Drive1.Drive) CD IN ??

Posted on 2001-08-29
4
Medium Priority
?
188 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 200 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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 Month18 days, 10 hours left to enroll

834 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