[Accessフォーム実行結果]
■ Access VBA 実行コード
Option Explicit
'空き容量を取得するWindowsAPI
Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" (ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency) As Long
'空き容量を取得を実行
Public Sub AcGetDiskFreeSpace(Drive As String, _
freeBytesAvailable As Currency, _
totalNumberOfBytes As Currency, _
totalNumberOfFreeBytes As Currency)
GetDiskFreeSpaceEx Drive, freeBytesAvailable, _
totalNumberOfBytes, totalNumberOfFreeBytes
'通貨型を10000倍すると取得する数値となる
freeBytesAvailable = freeBytesAvailable * 10000
totalNumberOfBytes = totalNumberOfBytes * 10000
totalNumberOfFreeBytes = totalNumberOfFreeBytes * 10000
End Sub
Private Sub コマンド1_Click()
'調べるフォルダ名
Dim sDir As String
'ユーザーが利用可能な空き容量
Dim freeBytesAvailable As Currency
'ディスク総容量
Dim totalNumberOfBytes As Currency
'ディスクの空き容量
Dim totalNumberOfFreeBytes As Currency
Dim s1 As String
sDir = "c:\"
AcGetDiskFreeSpace sDir, freeBytesAvailable, totalNumberOfBytes, _
totalNumberOfFreeBytes
'結果表示
Me!テキスト1 = "ドライブ:" & sDir & vbCrLf & _
"利用可能な" & vbCrLf & _
"空容量: " & Format$(Format$(freeBytesAvailable, "#,##0"), _
"@@@@@@@@@@@@@@@ Byte") & vbCrLf & _
"総容量: " & Format$(Format$(totalNumberOfBytes, "#,##0"), _
"@@@@@@@@@@@@@@@ Byte") & vbCrLf & _
"空容量: " & Format$(Format$(totalNumberOfFreeBytes, "#,##0"), _
"@@@@@@@@@@@@@@@ Byte")
End Sub