image picture path error

Posted on 2009-02-11
Last Modified: 2012-05-06
I have a sub form that contain an image control. The path of the image with change with program installations.  The problem Is how can I trap the error that says the path is not found.

When the form is opened I get a msgbox that conatins, "NameOfMyProgram can't open the file C:\somepath".  And this repeats twice before the form is loaded.

I have tried setting the path via Form_Load but I still get the error.  The image does display.
Break on all errors is selected in Error Trapping

How can I trap this error or set the image path correctly?
Private Sub Form_Load()

Forms!Options![TripSheetSelector_Sub].Form.TripSheetThumb1.Picture = CurrentProject.Path & "\Samples\tripsheet1_thumb.jpg"

End Sub

Open in new window

Question by:buzzcarter
    LVL 42

    Expert Comment

    I don't know how to trap the error.

    Maybe give this a try:

    Change the image to an embedded graphic that will act like a placeholder and permit the form to load successfully.  In the On Load event, then switch to the dynamic path:

    Me.YOURIMAGE.Picture= CurrentProject.Path & "\Samples\tripsheet1_thumb.jpg"
    Me.YOURIMAGE.PictureType = 1            'change linked image




    Author Comment

    No that did not work dgmg.  Still have the same error message.
    LVL 42

    Accepted Solution

    I'm thinking you still have a runtime reference to the invalid path.  When you change the image reference to "embedded", then the reference gets resolved at design time and the graphic becomes embedded in your .mdb file and should not produce a runtime error.

    Since you get the error message more than one time, I'm thinking you still must have not cleaned up all of the image references.   Convert the form to use all embedded graphics first, with no errors, and it should port from machine to machine just fine.  Then if you want to "externalize" the graphic to a different path on different machines, change it to a linked picture with the correct path during the on load event.


    Author Closing Comment

    Your were correct.  Thank You.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now