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.
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.
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.
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.
You can try the Dir() and Len() functions. Along the lines of
IIf(Len(Dir([PICT_LINK])) > 0, ...)
What does that field contain? It would need to be the full path.
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.
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?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
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
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])
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
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.