【问题标题】:Display attachment for specific record Microsoft Access显示特定记录的附件 Microsoft Access
【发布时间】:2014-11-01 16:11:31
【问题描述】:

为此,我尝试查阅 Google 和我的 Access 书籍,但没有成功。

问题来了:

如果您在 Access 中创建一个如下所示的表

附件字段名为 MyImage,包含 Bar 的图像,但不包含 Foo 的图像。

我创建了一个带有附件控件的表单,以便为不同的用户轻松添加、删除和显示图像。

我想要做的是能够在我的组合框中选择一个用户,并在附件控件中显示该用户的图像。

我该怎么做?

我通过进入设计视图并单击添加现有字段来创建附件控件。然后我将 MyImage 字段拖到表单中。我注意到如果 Foo 有图像,我会出现在附件控件中。所以控件似乎只看Foo。我认为属性表中有一个属性,我可以在我的 VBA 代码中使用它来更改附件控件正在“查看”的记录,但我找不到任何东西。有没有这样的属性,如果有,叫什么?

【问题讨论】:

    标签: vba ms-access


    【解决方案1】:

    以另一种方式解决。使用 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
    

    【讨论】:

      【解决方案2】:

      如何以编程方式在 ms 访问中将附件字段值检索到附件控件中

      我有一个表名EmployeeeInfo,其中有两个字段“EmployeeId”,“Attach”

      #Declare a sub routine 
      
      Private Sub ShowPic(id as integer)
       Me.RecordSource = "SELECT * FROM EMPLOYEEINFO WHERE EMPLOYEEID=" & id
       Me.atchmntControl.ControlSource = "attach"
      End Sub
      
      #Call the method
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多