Results 1 to 2 of 2
  1. #1
    KathyL is offline Advanced Beginner
    Windows 7 Access 2007
    Join Date
    Aug 2010
    Posts
    94

    With VB, how can you get the DB file size?

    I'm looking for VB code that will interrogate the PC system folder information, specifically the database file size, and return the database file size into a variable.
    Anyone know the code or MS function?
    Thanks.

    Update: I think I found code:

    Public Function getFileSize(sFilePath As String, Optional sSize As String) As Long



    On Error GoTo ErrHandler

    Dim nByteSize As Currency
    Dim nFileSize As Currency

    Const KILO As Long = 1024

    nByteSize = FileLen(sFilePath)

    If (UCase$(sSize) = "M") Then
    nFileSize = nByteSize / KILO / KILO
    ElseIf (UCase$(sSize) = "K") Then
    nFileSize = nByteSize / KILO
    Else
    nFileSize = nByteSize
    End If

    getFileSize = nFileSize

    Exit Function
    ErrHandler:

    MsgBox "Error in getFileSize( )." & vbCrLf & vbCrLf & _
    "Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
    Err.Clear

    End Function

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    try:
    Code:
    Function FileSize(strFile As String)
    
    '******************************************************************************
    '                                                                             *
    'Author: Adam Evanovich                                                       *
    'Date: 7/7/2006                                                               *
    'Purpose: Returns the size of the specified file.                             *
    '                                                                             *
    'Arguments:                                                                   *
    'strFile > Path of the File being evaluated.                                  *
    '                                                                             *
    '******************************************************************************
    
    On Error GoTo Err_Handle
    
    If GetAttr(strFile) <> 32 Then
       MsgBox "File not found..."
          GoTo Exit_Handle
    End If
    
       FileSize = CDbl(FileLen(strFile))
       
       FileSize = IIf(FileSize < (CDbl(1024)), _
                      CStr(Format(FileSize, "#,###")) & "B", _
                  IIf(FileSize < (CDbl(1024) * CDbl(1024)), _
                      CStr(Format(FileSize / CDbl(1024), "#,###.00")) & "KB", _
                  IIf(FileSize < (CDbl(1024) * CDbl(1024) * CDbl(1024)), _
                      CStr(Format(FileSize / CDbl(1024) / CDbl(1024), "#,###.00")) & "MB", _
                      CStr(Format(FileSize / CDbl(1024) / CDbl(1024) / CDbl(1024), "###,###.00")) & "GB" _
                  )))
    
    Exit_Handle:
       Exit Function
       
    Err_Handle:
       MsgBox (Err.Description)
          Resume Exit_Handle
    
    End Function '//LL
    the size of your opened db will not be accurate though. I believe each users that has it opened will bloat it just a little bit in size. sorry, didn't see the edit!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Import Text File Size Limit
    By wfbp in forum Import/Export Data
    Replies: 1
    Last Post: 11-04-2010, 09:05 AM
  2. File size smaller after saving
    By Pilotwings_64 in forum Access
    Replies: 1
    Last Post: 08-20-2010, 06:21 AM
  3. Access 2007 file size vs Excel
    By andrewalms in forum Access
    Replies: 4
    Last Post: 02-02-2010, 02:32 PM
  4. mdb file size limit
    By dr_ping in forum Access
    Replies: 1
    Last Post: 01-19-2009, 09:52 AM
  5. Replies: 2
    Last Post: 07-24-2006, 09:19 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums