7 minutes
ago: Please note that the webserver will soon get its weekly reboot at 4:00 am Eastern Time. You may continue to use the site as normal, but you will be logged off at that time. You should be able to log right back on immediately, however. If you are in the process of placing an order, please make sure to complete it as quickly as possible, or come back after the reboot. Thank you. Sorry for any inconvenience.
Dismiss
You have a folder full of images that you want to add to a database.
Create a Table called tblPictures with the following schema:
FieldName
DataType
PictureID
Autonumber
PicturePath
Text
PictureName
Text
PictureSize
Integer
Now you can create a Module in Access and add the following code.
Just call the Function passing in your folder.
ListFiles("D:\Folder\")
Option Compare Database
' Add Ref to Microsoft Scripting Runtime
Sub ListFiles(mySourcePath)
Dim Counter As Integer
Set myObject = New Scripting.FileSystemObject
Set mySource = myObject.GetFolder(mySourcePath)
On Error Resume Next
Dim db As Database
Dim rs As Recordset
Dim mysql As String
Set db = CurrentDb
mysql = "tblPictures"
Set rs = db.OpenRecordset(mysql, dbOpenDynaset)
For Each myFile In mySource.Files
rs.AddNew
rs![PicturePath] = myFile.Path
rs![PictureName] = myFile.Name
rs![PictureSize] = myFile.Size
rs.Update
Counter = Counter + 1
Next
' Clean up
rs.Close
db.Close
Set rs = Nothing
Set db = Nothing
Set myObject = Nothing
Set mySource = Nothing
MsgBox "Listed " & Counter & " Files."
End Sub