gpt4 book ai didi

ms-access - 使用 VBA 将图像导入 MS Access

转载 作者:行者123 更新时间:2023-12-04 06:32:28 25 4
gpt4 key购买 nike

我有一个包含数百张图像的目录,我想用这些图像在 Access 中创建和填充记录。我如何使用 VBA 做到这一点?我基本上想做:

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

最佳答案

选择目录:
因为有很多不同的方法可以做到这一点,我将把这部分留给你。 Here's some code if you want to use the Common 'Browse for Folder' Dialog window.

要在目录中查找每个图像:

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

关于ms-access - 使用 VBA 将图像导入 MS Access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5238299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com