Question

Currently I have a database system that has been designed to log the calls coming into a department. To help other agents on the phone system with information I allowed for attachments so photographs, letters etc. To allow for attachments to be added there is an attachments control on the form to allow for additional documentation to be added as mentioned above.

The problem is, I have found a lot of people are using the system to store large copies of manuals. Which is causing the file size of the database to shoot up exponentially.

What I would like to know is, is it possible to restrict the file size of an attachment through VBA? For example restrict it to 6MB.

Was it helpful?

Solution

To answer your question the following code will return the file size but as others mentioned above I don't think I would want to store attachments in an Access database your database will grow quickly and may become unstable.

Private Sub CheckFileSize(strMyFile)
  Dim objFileSys As Scripting.FileSystemObject
  Dim objMyFile As File
  Set objFileSys = CreateObject("Scripting.FileSystemObject")
  Set objMyFile = objFileSys.GetFile(strMyFile)
  If objMyFile.Size > 6000000 then
    MsgBox "File is too big.", vbokonly
  Else
    MsgBox "File is OK.", vbokonly
  End If
  Set objFileSys = Nothing
  Set objMyFile = Nothing
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top