Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Setting Image.Picture problem (XP/2000)

    I've found a problem with a form in my database. The code below sits in the OnCurrent event of the form and sets the picture property of the image control to a specified file path.

    When I first open the form I get Runtime Error 2001 as described below. Navigating through the other records causes no such problem


    If fso.FileExists(strImageIncPath) Then
    'BREAKS ON NEXT LINE OF CODE WHEN FORM IS FIRST OPENED WITH
    'Runtime error 2001 'You cancelled the previous operation
    'after pressing F8 when in break mode it continues quite happliy.
    Me.imgPhoto.Picture = strImageIncPath
    Else
    Me.imgPhoto.Picture = vbNullString
    'problem, named photo not in folder
    End If

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

    Re: Setting Image.Picture problem (XP/2000)

    I assume this is a timing problem - the On Current event may occur before the form is ready. What happens if you insert a line

    On Error Resume Next

    above the section of code you posted? Does the picture remain blank in the first record, or is is loaded after all (in some situations, the On Current event occurs several times in succession when a form is opened).

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Image.Picture problem (XP/2000)

    It's definitely a timing thing. If the form is design view then I switch to form view it doesn't error.

    After adding On Error resume Next I don't get a message but the picture on the first record remains blank.

    I've just taken that line out and added the following to the error handler

    If Err.number =2001 Then
    Resume
    Else
    'the normal error stuff
    End if

    Seem to work, no error message seen and then the image is set and displayed.

    Good or bad idea though?

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

    Re: Setting Image.Picture problem (XP/2000)

    Test it a few times (for example, close the database, reopen it and immediately open the form). If it works OK, keep this modification.

  5. #5
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Manchester, Gtr Manchester, England
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Setting Image.Picture problem (XP/2000)

    Seems ok, think I'll stick with it. I was just a little concerned something else could trigger the same error and maybe it'd get stuck in a loop.

    Anyway, that seems to not be the case so thanks for the suggestions <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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