2011-03-08 7 views
2

Access에서 레코드를 만들고 채우는 데 사용할 이미지가있는 디렉토리가 있습니다. VBA를 사용하여 어떻게합니까? 나는 기본적으로 수행 할 :VBA를 사용하여 MS Access로 이미지 가져 오기

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 
+0

당신이 "무엇을 의미합니까 레코드의 이미지 첨부 파일 필드에 이미지를 추가를하여 데이터베이스 또는 단지 파일 링크? – HK1

+1

데이터베이스에 이미지를 추가하는 것은 거의 좋은 생각이 아니며 예를 들어 SQL Server와 같이 신중하게 고려해야 할 필요가 있습니다.이 방법으로 해결할 수있는 문제를 말하고 싶을 수도 있습니다 – Fionnuala

+0

데이터베이스에 파일의 복사본을 저장하고 싶습니다. 좋은 생각이 아니라면 이미지 첨부 파일을 렌더링 할 수있는 Access의 첨부 파일 필드가있는 이유는 무엇입니까? 양식에 어떤 의미입니까? – Senior

답변

3

디렉토리를 선택 :이 작업을 수행하는 방법에는 여러 가지가
때문에, 나는 당신까지이 부분을 떠날거야. ? 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 
+0

덕분에, 이것을 출발점으로 사용하겠습니다! – Senior

관련 문제