Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  • Thread Tools
  1. New Lounger
    Join Date
    Sep 2003
    Location
    South Dakota, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Link to image (XP)

    Hello-
    I have a form where I want an image to show after I click a command button.
    The image path is linked in code in an On Click Event of the command button:

    Me.imgPic.Picture = "Cocuments and SettingsRmpaleoMy DocumentsPaleo_LocalitiesImages" & Me.[Loc_Number] & ".jpg"

    This pulls a jpeg from a folder stored with Access database.
    I have two questions-
    1. When I open the database, no images are shown (good!). When I click on the command button, the appropriate image is shown (good!). But if I move to or create a new record (after I have opened an image in a previous record) the previous record's image is shown. If I then click on the command button, the appropriate image is shown for the new record (good!). So, the button works, but I need it to either refresh with the new image when I change records or clear the image (so the user has to click on the button). I would prefer that the image was cleared (command cancelled). How?

    2. Not every record has an image, so I get an error message that it can't find the file (understandably). How can I avoid this?

    Ok-I have three: do I need to reference others in my database if I use their code? Where and how?

    I'm using HansV's code from the "Link to Images (2000) posts (283145) on August 10-11, 2003. They were very helpful getting me this far. Thank you, HansV!
    I'm using this method because the path will change when we get a new server, and I want the images linked-not embedded.
    I am learning as I go, so I know just enough to get me in trouble. Code is new to me, so be gentle.
    Thank you for your time,
    Delda

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,466
    Thanks
    2
    Thanked 39 Times in 39 Posts

    Re: Link to image (XP)

    In answer to your first two questions, rather than using a command button to get the appropriate image, I would put code in the OnCurrent event for the form to establish the image (if there is one - if not simply set the image path to either Null or ""). In the case where there is no image, allow the user to add one using a command button - you may also want to let the user edit the existing one, so you might need two buttons, and make the appropriate one visible.

    As to the third question, if you have used code pretty much verbatim, then I would certainly attribute it to the author in a comment. That's useful in case you need to revist the code so you can remember where you got it, and it helps if others have to dig into it in the future. And of course it gives the author his due.
    Wendell

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

    Re: Link to image (XP)

    In the attached zipped Access 97 database (you'll have to convert it to Access 2000 or 2002 format), you'll find code to handle images in forms and reports. You can copy/use/modify the code in it freely, there is no copyright on it, but you might mention that you originally got it from Woody's Lounge.
    Attached Files Attached Files

  5. New Lounger
    Join Date
    Sep 2003
    Location
    South Dakota, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link to image (XP)

    Thank you Hans and Wendall!
    This is what I did, in case anyone cares to know...

    I inserted an Image named imgPic --Not an Object Frame-- and replaced Picture Name with (none). Changed to Linked and Zoom.
    Added an On Click Event Procedure:

    Private Sub imgPic_Click()
    On Error GoTo Err_imgPic_Click
    Me.imgPic.Picture = "Cocuments and SettingsMy DocumentsRMpaleoPaleo_LocalitiesImages" & Me.[Loc_Number] & ".jpg"
    Exit_imgPic_Click:
    Exit Sub
    Err_imgPic_Click:
    MsgBox ("Sorry, no image available.")
    Resume Exit_imgPic_Click
    End Sub

    I set my Form's OnCurrent to 'remove' any image remaining from the previously viewed record:

    Private Sub Form_Current()
    Me.imgPic.Picture = (none)
    End Sub

    This allows me to click on the image frame to view the current record's image and removes it when I go to the next record. This way it doesn't have to load for each record and I can move my database and photos without having to change the path for each record in the table. All I have to do is change my path in my Event Procedure to the new location.

    Unfortunately, in order to change the path, you have to be in Design View.

    Thanks for your help, guys!
    Delda

  6. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Link to image (XP)

    You might put the path in a text box, or you might create a small dedicated "settings" table to store information like this; you can retrieve the path from the table (for instance using DLookup). That way, you won't have to modify the design of the form if you want to change the path.

  7. New Lounger
    Join Date
    Sep 2003
    Location
    South Dakota, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link to image (XP)

    wow-
    I made it work!
    I made a table ImageSettings with fields ImagePath and PathID. Set my form's image OnClick event to;
    Me.imgPic.Picture = DLookup("[ImagePath]", "[ImageSettings]", "[PathID]=1") & Me.[Loc_Number] & ".jpg"

    and it pulls it right up! Forgive me for including this, but as a newbie I find it helpful when the obvious is stated.
    Thank you Hans! This will make my boss verrry happy in case I leave. Woody's Lounge has been very helpful, and the response time is excellent. Even for a paleontologist who has never taken a programming class before!

    Delda

  8. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Link to image (XP)

    Congratulations! It is always nice if you're able to work it out yourself (with the help of a little hint).

  9. New Lounger
    Join Date
    Feb 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link to image (XP)

    Dear Hans,
    From your attached database, when you click insert button in frmInventory the file picker Dialog box jump to the Application folder(one that contain the .mdb file), that is of great convenience!. But if I want it to jump right to the specified subfolders (eg. the folders each of which named after each kid's name in the table that contains kid's pictures.) and all these folders are the subfolders in Application folder, how can I do that.
    Thanks in advance. suwat.

  10. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Link to image (XP)

    The file picker dialog is controlled by the OPENFILENAME structure passed to the OpenDialog function. One of the members of this structure is lpstrInitialDir; in the database I posted, this is not set explicitly, but you can specify it if you like. You would do it like this in the cmdInsertPic_Click procedure (in the code behind frmInventory):

    ...
    With OFN
    .lpstrInititialDir = "C:YourFolderYourSubfolder"
    ...
    End With
    ...

  11. New Lounger
    Join Date
    Feb 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link to image (XP)

    Dear Hans,
    It works! thank you mery much.
    One more question.
    File picker dialog greatly help me pick the desired files from any specified folder to store in a field of the table. But if I want the path to the folder itself to store in a field, how can I use this dialog to do that?
    Thanks. Suwat

  12. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Link to image (XP)

    The GetFolder function in <post#=271140>post 271140</post#> by Don Ceraso demonstrates how to let the user browse for a folder instead of a file.

  13. New Lounger
    Join Date
    Feb 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link to image (XP)

    Dear Hans,
    The GetFolder function help me fullfil my requirement perfectly.
    Thank you very much , again.
    suwat.

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

    Re: Link to image (XP)

    Hi HansV,
    I try the code that is in your image demo database and it work very nice. I am having a problem that i cant figure it out. My database has tabs and on the initial tab the "imgPicture box" and the command buttons are displaying. I can insert images when i click on the insert command, but when I press the next record the same image still there for every record. I am breaking my head with this. Any help is very welcome.

  15. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Link to image (XP)

    The form in my demo database has an On Current event procedure:
    <code>
    Private Sub Form_Current()
    On Error GoTo HandleErr
    If Not IsNull(<!t>[PicFile]<!/t>) Then
    <!t>[imgPicture]<!/t>.Picture = <!t>[PicFile]<!/t>
    SysCmd acSysCmdSetStatus, "Image: '" & <!t>[PicFile]<!/t> & "'."
    Else
    <!t>[imgPicture]<!/t>.Picture = ""
    SysCmd acSysCmdClearStatus
    End If
    Exit Sub

    HandleErr:
    If Err = 2220 Then
    <!t>[imgPicture]<!/t>.Picture = ""
    SysCmd acSysCmdSetStatus, "Can't open image: '" & <!t>[PicFile]<!/t> & "'"
    Else
    MsgBox Err.Description, vbExclamation
    End If
    End Sub
    </code>
    This procedure takes care of displaying the correct picture as the user moves from record to record.

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

    Re: Link to image (XP)

    Thank you again, It work perfect. I forgot about that; I had a previous form_current for my records display. ;-).

Page 1 of 2 12 LastLast

Posting Permissions

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