|
|

Determining the size of the Hard Drive from Access
If you wish to check the size of the user's hard drive from within Access, for example before creating a large file, then you will need to use a call to an API, GetDiskFreeSpaceExA, to do this. Previously, you would use the GetDiskFreeSpace API, but now that Hard Drives are getting larger, it cannot cope with ones larger than 2Gb. Below are sample functions using this code that will return the number of bytes free on the drive, the toal number of bytes on the drive, and also how many bytes have been used. Just copy the code below into a module:
Option Compare Database
Option Explicit
Private Declare Function apiGetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
lpcurFreecurUserBytes As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfcurFreeBytes As Currency) As Long
Function fHDDSpaceTotal(strDriveName As String) As Double
Dim lngReturn As Long
Dim curTotalBytes As Currency
Dim curFreeBytes As Currency
Dim curUserBytes As Currency
If Right(strDriveName, 1) <> "\" Then strDriveName = strDriveName & "\"
lngReturn = apiGetDiskFreeSpaceEx(strDriveName, curUserBytes, curTotalBytes, curFreeBytes)
If lngReturn <> 0 Then fHDDSpaceTotal = curTotalBytes * 10000
End Function
Function fHDDSpaceFree(strDriveName As String) As Double
Dim lngReturn As Long
Dim curTotalBytes As Currency
Dim curFreeBytes As Currency
Dim curUserBytes As Currency
If Right(strDriveName, 1) <> "\" Then strDriveName = strDriveName & "\"
lngReturn = apiGetDiskFreeSpaceEx(strDriveName, curUserBytes, curTotalBytes, curFreeBytes)
If lngReturn <> 0 Then fHDDSpaceFree = curFreeBytes * 10000
End Function
Function fHDDSpaceUsed(strDriveName As String) As Double
Dim lngReturn As Long
Dim curTotalBytes As Currency
Dim curFreeBytes As Currency
Dim curUserBytes As Currency
If Right(strDriveName, 1) <> "\" Then strDriveName = strDriveName & "\"
lngReturn = apiGetDiskFreeSpaceEx(strDriveName, curUserBytes, curTotalBytes, curFreeBytes)
If lngReturn <> 0 Then fHDDSpaceUsed = (curTotalBytes - curFreeBytes) * 10000
End Function
|
Top
HOME |
NEW |
TABLES |
QUERIES |
FORMS |
REPORTS |
GENERAL |
API |
DOWNLOADS |
TUTORIAL |
RESOURCES
E-MAIL
Copyright & Disclaimer
|
| |