Results 1 to 12 of 12
  1. #1
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86

    Can an image control tell if the file exists?


    I have an image that gets controlled by a link. If the file does not exist it shows no image. Can Access see if the file exists so that if it does not I can put in a default image instead?

    Thank you for your help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    What do you mean by a 'link' - a text field has image file path? Are you using an Image control? Could save default image path into record. Otherwise, an IIf() expression in Image ControlSource property can conditionally display image.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    Image control that links to text with file location. I do have a iif statement written but it does not check to see if a file exists. If it does not exist it just goes white instead of showing the default image that says picture not available. =IIf(IsNull([PICT_LINK]),"S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg",[PICT_LINK]) All the links exist but the all the actual files are a work in progress.
    Quote Originally Posted by June7 View Post
    What do you mean by a 'link' - a text field has image file path? Are you using an Image control? Could save default image path into record. Otherwise, an IIf() expression in Image ControlSource property can conditionally display image.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can try the Dir() and Len() functions. Along the lines of

    IIf(Len(Dir([PICT_LINK])) > 0, ...)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    Tried this same result, all white pic.
    Code:
    =IIf(Len(Dir([PICT_LINK]))>0,[PICT_LINK],"S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg")
    Quote Originally Posted by pbaldy View Post
    You can try the Dir() and Len() functions. Along the lines of

    IIf(Len(Dir([PICT_LINK])) > 0, ...)

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What does that field contain? It would need to be the full path.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Okay, then need VBA function to check if file exists. Then call function in Image ControlSource:

    =IIf(FileExist([PICT_LINK]), [PICT_LINK], "S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg")

    The function:

    Function FileExist(strPath AS String) As Boolean
    FileExist = Dir(strPath) <> ""
    End Function
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    I put it in exactly as you said and all the pics went to white. Put the function in a module and changed the control to the if statement. Not sure why it did not work. Is there a way to debug it?
    Quote Originally Posted by June7 View Post
    Okay, then need VBA function to check if file exists. Then call function in Image ControlSource:

    =IIf(FileExist([PICT_LINK]), [PICT_LINK], "S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg")

    The function:

    Function FileExist(strPath AS String) As Boolean
    FileExist = Dir(strPath) <> ""
    End Function

  9. #9
    caniread is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2015
    Posts
    86
    Here is what I was able to do in a current event to make it work. Would prefer to do it in a query column instead, using a function in a module.

    Code:
    If Dir(PICT_LINK) = "" Then    'MsgBox "Directory doesn't exist"
        Me.Image105.Picture = "S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg"
        Exit Sub
        Else
         Me.Image105.Picture = [PICT_LINK]
        End If

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The nearest equivalent to that for a query would probably be:

    IIf(Dir(PICT_LINK) = "","S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg",[PICT_LINK])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Oh, if you want a function in a module, have it accept the field as an input variable and output a string. Adapt your code:

    Code:
    If Dir(Variablename) = "" Then
      FunctionName = "S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg"
    Else
      FunctionName = VariableName
    End If
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Tested and worked for me.

    However, function will error if field is null. Is null field a possibility?

    =IIf(FileExist(Nz([Pic],"C:\none.png")),[Pic],"S:\Maintenance\Parts Database\Parts Pictures\No_Image_Available.jpg")

    Or as Paul shows, hard code the alternate image in function.

    I tried DIR() in query and it doesn't work (undefined function), which is why I wrote the VBA function.

    Function can be called from query if function is in a general module.

    Is this a multi-user split db?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 8
    Last Post: 07-20-2018, 03:29 PM
  2. Replies: 6
    Last Post: 06-04-2018, 06:46 AM
  3. Replies: 2
    Last Post: 03-14-2018, 11:10 AM
  4. Replies: 3
    Last Post: 07-13-2015, 12:07 PM
  5. Replies: 1
    Last Post: 09-27-2010, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums