添加图片到表单中使用路径外部源 [英] Adding Images into Forms from External Sources using Paths

查看:197
本文介绍了添加图片到表单中使用路径外部源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找各地在谷歌找到一个更好的方式来显示图像的访问,而无需实际插入图像到数据库中。

I've been searching around on Google to find a better way to show images in Access without actually inserting the image into the database.

我发现这篇文章 http://support.microsoft.com/kb/285820 通过这个线程的<一个href="http://stackoverflow.com/questions/40112/is-there-a-way-to-get-ms-access-to-display-images-from-external-files">Is有没有办法让MS-访问显示从外部文件图像,这将进入非常详细的关于如何通过文件夹/文件设置路径的图片,和它的伟大工程,对于一个设定的画面。不过,我想不同的画面显示,当我切换到不同的记录。

I found this article 'http://support.microsoft.com/kb/285820' via this thread 'Is there a way to get ms-access to display images from external files' which goes into great detail on how to set paths to pictures through folders/files, and it works great, for a 'set' picture. However, I want a different picture to display when I switch to a different record.

下面是文章中的code:

Here is the code from the article:

Option Compare Database
Option Explicit

Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
On Error GoTo Err_DisplayImage

Dim strResult As String
Dim strDatabasePath As String
Dim intSlashLocation As Integer

With ctlImageControl
    If IsNull(strImagePath) Then
        .Visible = False
        strResult = "No image name specified."
    Else
        If InStr(1, strImagePath, "\") = 0 Then
            ' Path is relative
            strDatabasePath = CurrentProject.FullName
            intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
            strDatabasePath = Left(strDatabasePath, intSlashLocation)
            strImagePath = strDatabasePath & strImagePath
        End If
    .Visible = True
    .Picture = strImagePath
    strResult = "Image found and displayed."
    End If
End With

Exit_DisplayImage:
    DisplayImage = strResult
    Exit Function

Err_DisplayImage:
    Select Case Err.Number
        Case 2220       ' Can't find the picture.
            ctlImageControl.Visible = False
            strResult = "Can't find image in the specified name."
            Resume Exit_DisplayImage:
        Case Else       ' Some other error.
            MsgBox Err.Number & " " & Err.Description
            strResult = "An error occurred displaying image."
            Resume Exit_DisplayImage:
    End Select
End Function

我有我需要将一行code,指出类似,显示图像,其中Image.ID =ID,但我想不出哪里把它没有得到错误的感觉。我是不是过度期待的东西也许,还是我处理这个错误的方式?我只是不希望扰乱我的数据库,内存明智的,有.BMP图像,但我觉得我将不得不这样做。

I have a feeling that I need to place a line of code that states something like, show image where Image.ID = "ID", but I can't figure out where to put it without getting errors. Am I over-looking something perhaps, or am I approaching this the wrong way? I just don't want to clutter my database, memory-wise, with .bmp images, but I feel like I am going to have to.

解决:一个更容易的解决方法戈德·汤普森已经在下方的注释中描述。而从我自己的经验,使用这种方法的.bmp图像离开的画面变形,出对比度。我测试的.JPG图像和它的工作完美!我希望这可以帮助其他人谁遇到了问题类似的问题发现这个职位有帮助的。

SOLVED: A much easier solution is as Gord Thompson has described below in the comments. And from my own experience, using this method for .bmp images leaves the picture distorted and out of contrast. I tested the image for .jpg and it worked perfectly! I hope this helps others who are having trouble with similar problems finds this post helpful.

推荐答案

您引用的Microsoft支持本文适用于Access 2003中在Access 2010(或更高版本)存在的的简单的方法吗它。所有你需要做的是放置一个Image控件的形式,并将其绑定到包含路径图像文件中的表中的字段。

The Microsoft Support article you cited applies to Access 2003. In Access 2010 (and later) there is a much simpler way to do it. All you need to do is place an Image control on the form and bind it to the field in your table that contains the path to the image file.

例如,用[职员表像这样

For example, with an [Employees] table like this

EmployeeID  FirstName  LastName  PhotoPath                        
----------  ---------  --------  ---------------------------------
         1  Gord       Thompson  C:\Users\Public\Pictures\Gord.jpg
         2  Hank       Kingsley  C:\Users\Public\Pictures\Hank.png

您可以使用一个Image控件的控制源是[PhotoPath]字段...

you could use an Image control whose Control Source is the [PhotoPath] field ...

...和图像将自动从指定的文件中检索

... and the image will automatically be retrieved from the file specified

没有VBA必需的。

另请注意,图像文件没有被.bmp文件。

Note also that the image files do not have to be .bmp files.

这篇关于添加图片到表单中使用路径外部源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆