Question:
in MS Access how to link products field in a form to pictures in folder on the H Disk?
Sinan A
2008-12-12 23:34:41 UTC
the link
http://www.tek-tips.com/faqs.cfm?fid=279
solved part of the problem, but I get an error message when there is no picture for some of the products!! I need the program not to do any thing if there is no picture just to show picture if there is one in the folder
Three answers:
2008-12-13 09:31:22 UTC
Previous answer was close to right, written incorrectly; there is no "FileExists" class in VBScript; it's a method of the FileSystemObject class.



Private Sub Form_Current()

If Me![ID] <> 0 Then

Dim strPath = "p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

Set objFSO = CreateObject( "Scripting.FileSystemObject" )

If objFSO.FileExists( strPath ) Then

Me!Image14.Picture = strPath

Label20.Caption = "File: " & strPath

End If

End If

Set objFSO = Nothing

End Sub



If you want to have a default "No picture" image, e.g., nopicture.jpg, that shows whenever a picture cannot be found:



Private Sub Form_Current()

If Me![ID] <> 0 Then

Dim strPath = "p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

Set objFSO = CreateObject( "Scripting.FileSystemObject" )

If Not objFSO.FileExists( strPath ) Then

strPath = "p\ViewPhotos\Photos\" & "noimage.jpg"

End If

Me!Image14.Picture = strPath

Label20.Caption = "File: " & strPath

End If

Set objFSO = Nothing

End Sub
?
2016-12-10 15:35:49 UTC
try this - In layout view, ideal click on the field and pass to residences. on the format tab, discover the photograph get entry to, click interior the field next to it, then click on the "..." that look at the back of it and skim to the photograph you desire to apply. make advantageous that "photograph form" (must be ideal below the photograph assets) is set to embedded.
2008-12-12 23:54:00 UTC
instead of:



If Me![ID] <> 0 Then

Me!Image14.Picture = "p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

Label20.Caption = "File: " & " p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

End If



you have to check if the image file exists, like this:



If Me![ID] <> 0 Then

if FileExists("p:\ViewPhotos\Photos\" & Me![ID] & ".jpg")

Me!Image14.Picture = "p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

Label20.Caption = "File: " & " p:\ViewPhotos\Photos\" & Me![ID] & ".jpg"

End If

End If


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...