Solved

why doesn't GetDriveType(DrivetypeCode) work?

Posted on 2004-03-23
4
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

623 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