开发者

Importing images into MS Access using VBA

I hav开发者_如何学Ce a directory with hundreds of images that I would like to use to create and populate records in Access. How do I do this using VBA? I essentially want to do:

choose directory
for each image in the directory:
     create new record
     set "name" field of the record to the file name
     add the image to the "image" attachment field of the record


Choose Directory:
Because there are many different ways to do this, I'll leave this part up to you. Here's some code if you want to use the Common 'Browse for Folder' Dialog window.

To find each image in a directory:

Public Sub LogPictureFilesToDatabase(sFolderPath As String)
    Dim sFileName As String
    sFileName = Dir(sFolderPath)

    Do Until sFileName = ""
        Select Case LCase(Right(sFileName, 4))
            Case ".jpg", ".gif", ".bmp"
                'Put your SQL Insert Statement here
                'Or you can use DAO or ADO to add new records instead, if you prefer
                'You may also want to use a function to insert a blob if you want to save
                'the file inside the database, which I do not recommend
            Case Else
                'Ignore other file extentions
        End Select
        sFileName = Dir 'Get next file
    Loop
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜