Solved

why doesn't GetDriveType(DrivetypeCode) work?

Posted on 2004-03-23
4
404 Views
Last Modified: 2008-03-17
Access 2000 XP
I get a '1' back as the DrivetypeCode regardless of whether its running on a local or networked computer.

Any suggestions how to use this or suggest new code to determine if the db is on a networed or local computer.

Thanks

Elton

'Check if this is a network drive
'Return  codes
'#####################
'The following codes are listed for reference
'  DRIVE_UNKNOWN = 0
'  DRIVE_ABSENT = 1
'  DRIVE_REMOVABLE = 2
'  DRIVE_FIXED = 3
'  DRIVE_REMOTE = 4
'  PDRIVE_CDROM = 5
'  DRIVE_RAMDISK = 6
'#####################
MsgBox GetDriveType(DrivetypeCode)
0
Comment
Question by:katzwhite
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:heer2351
heer2351 earned 300 total points
ID: 10661468
Make sure you include a colon behind the drive letter, example:

MsgBox  GetDriveType("E:")
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 200 total points
ID: 10661496
Try this

Private Function CurrentDriveType() As String
    Dim fso As Object ' File System Object
    Dim drv As Object ' Drive
   
    Set fso = CreateObject("scripting.filesystemobject")
   
    Set drv = fso.GetDrive(fso.GetDriveName(App.Path))
    CurrentDriveType = Choose(drv.DriveType + 1, "Unknown", "Removable", "Fixed", "Network", "CD-ROM", "RAM Disk")
   
    Set drv = Nothing
    Set fso = Nothing
End Function
0
 
LVL 23

Accepted Solution

by:
heer2351 earned 300 total points
ID: 10661558
@capricorn1,

GetDriveType is an API function which does not require a scripting object.

Private Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

When you call this function without a colon behind the drive letter you do get a DRIVE_ABSENT (1) back all the time.
0
 

Author Comment

by:katzwhite
ID: 10662438
capricorn1 & heer2351,

You've both helped me understand the code (I'm not a very good VBA programmer).  I didn't understand I had to include the drive letter of the drive I needed checked, makes sense now.

I'm going to split the points.

Thanks for the help.

Elton
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

743 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

16 Experts available now in Live!

Get 1:1 Help Now