Check The A: Drive For Diskette

NitherWise

New Member
Joined
Nov 3, 2002
Messages
36
Is there a macro or some kind of code that I could write to have Access check the A: drive for a diskette before it performs an import?

The problem I'm having now is that Access goes through the process of importing the file and displaying the message box that the import was successful even if the drive is empty.

Thanks for your help.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Well, I tested this in VB6 and Excel 2000 Don't have access available

This will test for a floppy disk in drive A:\, but if your code does it's stuff and reports no issues without the disk in, I think you have bigger issues with it, this might help you resolve some of them:

<pre style="background:#F4F4F4;"><font color="#000000" size=2><font color="#000088" size=2>Function</font> DiskInFloppy(Drive <font color="#000088" size=2>As</font> <font color="#000088" size=2>String</font>) <font color="#000088" size=2>As</font> <font color="#000088" size=2>Boolean</font>
<font color="#000088" size=2>On</font> <font color="#000088" size=2>Error</font> <font color="#000088" size=2>GoTo</font> nodisk

<font color="#000088" size=2>ChDir</font> Drive
DiskInFloppy = <font color="#000088" size=2>True</font>
<font color="#000088" size=2>Exit</font> <font color="#000088" size=2>Function</font>

nodisk:
<font color="#000088" size=2>If</font> Err.Number = 75 <font color="#000088" size=2>Then</font> DiskInFloppy = <font color="#000088" size=2>False</font>
<font color="#000088" size=2>End</font> <font color="#000088" size=2>Function</font>



<font color="#000088" size=2>Sub</font> hhd()
<font color="#000088" size=2>If</font> DiskInFloppy("A:") <font color="#000088" size=2>Then</font>
MsgBox "Floppyful"
<font color="#000088" size=2>Else</font>
MsgBox "Floppyless"
<font color="#000088" size=2>End</font> <font color="#000088" size=2>If</font>
<font color="#000088" size=2>End</font> <font color="#000088" size=2>Sub</font>
</font></pre>


HTH

Matt
 
Upvote 0
Try FileSystemObject.


Code:
Function CheckDrive() As Boolean
Dim fso As Object
Dim drv As Object
Dim driveletter As String
    
    driveletter = "A:"
    Set fso = CreateObject("Scripting.FileSystemObject")
    If fso.DriveExists(driveletter) = False Then
        MsgBox "Device unavailable.", vbOKOnly + vbExclamation, "Error"
        Exit Function
    End If
    Set drv = fso.GetDrive(driveletter)
    If drv.IsReady Then
        CheckDrive = True
    Else
        CheckDrive = False
    End If
End Function

Usage :

Code:
....
if CheckDrive=False then
  'Not ready
  'Stop execution
else
  'Ready
  'Do Import
End if
....


I hope it helps.

Suat
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,327
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top