Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use hyperlinks to get a form to show a picture (Access 2000)

    How do I go about getting a picture to show on a form that has a record source without making the field in the table OLE Object? I was thinking you would make the field a hyperlink and have all the pictures in the same folder. But that is as far as can get it. I do not want the hyperlink to show in text on the form and then you click on the text and the picture opens. When the form loads I want the picture to already be there on the form. I hope this can be done without having to store all the pictures in the table. This makes the database extremely large and cumbersome.

    Mike

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    The recommended approach is to store the path and filename of the image in a text field in the database, and to use a standard image control (not an unbound OLE control) and some VBA code to display the image. The database attached to <post#=296892>post 296892</post#> demonstrates how to do this in a form and in a report. The images can be .bmp, .jpg, .gif, .png, .wmf, .tif and several other graphics formats.

  3. #3
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    Thanks Hans,

    I got it to work. Now I am having some puzzling problems. I got the database you suggested I look at. I determined that the form and code that was in the database was exactly what I need so I imported it into my database, changed the datasource and correspondingly the field names. This worked.

    I then needed to add a second image and "insert" and "delete" buttons for the second image. This is where my problems begin. As far as I can tell, I have me the necessary chages to the code. However, when I try to insert the a picture into the second image I get the following error:

    "The field is too small to accept the amount of data you attempted to add. Try inserting or pasting less data."

    The following code is the insert buttons for the first the first and second images. It also includes the "On Current" code.


    Private Sub cmdInsertPic_Click()
    Dim OFN As OPENFILENAME
    On Error GoTo Err_cmdInsertPic_Click

    ' Set options for dialog box.
    With OFN
    .lpstrTitle = "Images"
    If Not IsNull([Picrture_Real]) Then .lpstrFile = [Picrture_Real]
    .flags = &H1804 ' OFN_FileMustExist + OFN_PathMustExist + OFN_HideReadOnly
    .lpstrFilter = MakeFilterString("Image files (*.bmp;*.gif;*.jpg;*.wmf)", "*.bmp;*.gif;*.jpg;*.wmf", _
    "All files (*.*)", "*.*")
    End With

    If OpenDialog(OFN) Then
    [Picrture_Real] = OFN.lpstrFile
    [imgPicture].Picture = [Picrture_Real]
    SysCmd acSysCmdSetStatus, "Afbeelding: '" & [Picrture_Real] & "'."
    End If
    Exit Sub

    Err_cmdInsertPic_Click:
    MsgBox Err.Description, vbExclamation
    End Sub


    Private Sub cmdInsertPic2_Click()
    Dim OFN As OPENFILENAME
    On Error GoTo Err_cmdInsertPic2_Click

    ' Set options for dialog box.
    With OFN
    .lpstrTitle = "Images"
    If Not IsNull([Picture3]) Then .lpstrFile = [Picture3]
    .flags = &H1804 ' OFN_FileMustExist + OFN_PathMustExist + OFN_HideReadOnly
    .lpstrFilter = MakeFilterString("Image files (*.bmp;*.gif;*.jpg;*.wmf)", "*.bmp;*.gif;*.jpg;*.wmf", _
    "All files (*.*)", "*.*")
    End With

    If OpenDialog(OFN) Then
    [Picture3] = OFN.lpstrFile
    [imgPicture2].Picture = [Picture3]
    SysCmd acSysCmdSetStatus, "Afbeelding: '" & [Picture3] & "'."
    End If
    Exit Sub

    Err_cmdInsertPic2_Click:
    MsgBox Err.Description, vbExclamation
    End Sub


    Private Sub Form_Current()
    On Error GoTo HandleErr
    If Not IsNull([Picrture_Real]) Then
    [imgPicture].Picture = [Picrture_Real]
    SysCmd acSysCmdSetStatus, "Image: '" & [Picrture_Real] & "'."
    Else
    [imgPicture].Picture = ""
    SysCmd acSysCmdClearStatus
    End If

    If Not IsNull([Picture3]) Then
    [imgPicture2].Picture = [Picture3]
    SysCmd acSysCmdSetStatus, "Image: '" & [Picture3] & "'."
    Else
    [imgPicture2].Picture = ""
    SysCmd acSysCmdClearStatus
    End If
    Exit Sub

    HandleErr:
    If Err = 2220 Then
    [imgPicture].Picture = ""
    [imgPicture2].Picture = ""
    SysCmd acSysCmdSetStatus, "Can't open image: '" & [Picrture_Real] & " or " & [Picture3] & "'"
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub


    Thanks
    Mike

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    The code tries to store the complete path and file name of the selected picture in the 'Picrture_Real' field. What is the size of this field? In the demo database, the PicFile field can contain 200 characters.

  5. #5
    2 Star Lounger
    Join Date
    Nov 2004
    Location
    Lexington Park, Maryland, USA
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    That worked. I increased the size to 250 and everything was good.

    Thanks
    Mike

  6. #6
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    Hi, I used the first set of the code to insert pic into my form with 250 character in the field. It was working properly for the last 5 months. Today I received this message that is attached to this post. I try to Compact and repair the database, it did not work. I tried to open a sample database that Hans created in a previous post, I tried to insert a pic from it and the same message pop up. Any Help.
    Attached Images Attached Images

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    Can you do a little experiment? Locate some image files of different types, for example a .bmp file, a .gif file, a .jpg file and a .png file. Try to insert each of these in the demo database.
    Do they all behave the same, or do some succeed and others fail - if so, which ones?

  8. #8
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    This is the demo that i am using to compare to my form. I tried to insert jpg and gif files and the message came up. I used bmp files and it got inserted but the image looks super nasty. Also I noticed that the image location it is saved in the field but it can't display; instead, the message comes up, I delete the image from that record and the message will not come up for the particular record when i scroll thru the records.
    Attached Files Attached Files

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    The demo works on my PC (I created it <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

    Perhaps the graphics filters aren't installed on your PC, or damaged. I would run Office setup again (from the Add/Remove Programs control panel), choose the option to add/remove components, and try to see if some filters were left out. You can also try a repair installation.

  10. #10
    2 Star Lounger
    Join Date
    Jul 2005
    Location
    North Carolina, USA
    Posts
    195
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Use hyperlinks to get a form to show a picture (Access 2000)

    Thank Hans. Now, I know it is not the database

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •