2014-11-01 92 views
0

我試過去諮詢Google和我的Access本書,但沒有運氣。如果您在Access中創建一個表,看起來像這樣特定記錄的顯示附件Microsoft Access

enter image description here

附件字段被稱爲MYIMAGE幷包含用於酒吧,但不是爲富圖像

這裏談到的問題。

我使用附件控件創建了一個表單,以便爲不同的用戶輕鬆添加,刪除和顯示圖像。

enter image description here

我想要做的是能挑到我的組合框中選擇一個用戶,並在附件控制用戶顯示圖像。

我該怎麼做?

我通過進入設計視圖創建附件控件,然後單擊添加現有字段。然後我將MyImage字段拖到窗體上。我注意到如果Foo有圖片,我會在附件控件中顯示。所以這個控件似乎只看Foo。我認爲屬性表中有一個屬性,我可以在我的VBA代碼中使用它來更改附件控件正在「查看」哪個記錄,但我找不到任何東西。有沒有這樣的財產,如果有,那叫什麼?

回答

0

以另一種方式解決。使用FileDialog打開用戶可以選擇文件的對話框。

將文件讀入數據庫並顯示在ImageBox中。我現在唯一的問題是如何從數據庫檢索附件並顯示它。

Private Sub Command1_Click() 
     ' Note that you need to add a reference to Microsoft Office 
     ' 15.0 Object Library using Tools -> References... for the 
     ' file picker to work 
     With Application.FileDialog(msoFileDialogFilePicker) 
      ' Prevent multiple selections 
      .AllowMultiSelect = False 
      ' Set the caption of the dialog box 
      .Title = "Please pick a signature" 
      ' Add filters for common image formats 
      .Filters.Clear 
      .Filters.Add "Joint Photographic Experts Group (JPG)", "*.JPG" 
      .Filters.Add "Joint Photographic Experts Group (JPEG)", "*.JPEG" 
      .Filters.Add "Portable Network Graphics", "*.PNG" 
      .Filters.Add "Bitmap", "*.BMP" 
      If .Show = True Then ' File selected 
      For Each imagePath In .SelectedItems 
       ' Instantiate the parent recordset 
       Set rsImage = CurrentDb.OpenRecordset("Image") 
       ' Step to record (We know record exist, else add rsImage.EOF) 
       While rsImage.Fields("ID") <> 3 ' Or whatever 
        rsImage.MoveNext 
       Wend 
       ' Instantiate the child recordset 
       Set rsPictures = rsImage.Fields("MyImage").Value 
       ' Clear attachments (we only want one attachment at a time) 
       Do While Not rsPictures.EOF 
        rsPictures.Delete 
        rsPictures.MoveNext 
       Loop 
       ' Activate edit mode 
       rsImage.Edit 
       ' Add the attachment selected by the user 
       rsPictures.AddNew 
       rsPictures.Fields("FileData").LoadFromFile imagePath 
       rsPictures.Update 
       ' Update the parent record 
       rsImage.Update 
       ' Set the content of the ImageBox 
       Me.ImageBox.Picture = imagePath 
      Next 
      Else ' User clicked "Cancel" 

      End If 
     End With 
    End Sub 

enter image description here