My Assistant
![]() ![]() |
|
|
Aug 4 2004, 03:58 PM
Post
#1
|
|
|
New Member Posts: 12 From: Missouri |
What I am doing is trying to get pictures to work in a form. I have a lot of pictures in a folder with their names the name of their key in access. Then what I'm doing is setting a picture, on current event, to the path of that picture. Example: Me.imgEmpty.Picture = "C:\WINDOWS\Desktop\Neon Pictures\" & Me.NeonID.Value & ".jpg". It crashes when there is no picture for a NeonID.Value, when there is no picture of that sign available. How do I create an if statement to make sure that there is a picture corresponding to NeonID to make sure there is a picture to display?
|
|
|
|
Aug 4 2004, 04:43 PM
Post
#2
|
|
|
UtterAccess VIP Posts: 5,597 From: St. Louis, MO |
You can use the Dir() function to test the existence of a file. If this is the picture associated with an image control then do it in the Form_Load event
CODE Private Sub Form_Load() If Len(Dir("C:\WINDOWS\Desktop\Neon Pictures\" & Me.NeonID.Value & ".jpg")) > 0 Then Me.imgEmpty.Picture = "C:\WINDOWS\Desktop\Neon Pictures\" & Me.NeonID.Value & ".jpg" End If End Sub The Dir Function will return whatever Me.NeonID.Value & ".jpg" equals if the file exists and and empty string if the file does not. The Len Function returns the lenght of a string. |
|
|
|
Aug 4 2004, 05:18 PM
Post
#3
|
|
|
UtterAccess VIP Posts: 12,201 From: Tacoma, WA. |
Brians solution will work but I approach it a little differently using the code below:
CODE Dim strPath As String Dim strDir As String If Nz(Len(Me.PlayLogo), 0) > 0 Then strPath = CurrentProject.Path & "\PlayerLogo\" & Me.PlayLogo strDir = Dir(strPath) If Dir(strPath) <> "" Then Me.ImgPlaylogo.Picture = strPath Me.ImgPlaylogo.Visible = True Me.LblplayLogo.Visible = False End If Else Me.ImgPlaylogo.Visible = False Me.LblplayLogo.Visible = True End If End Sub The me.lblplaylogo is a label with No image Available as the text and becomes visible when there is no ImgplayLogo available. Just another approach that may help of course your field name/s will be different and need changing This is also placed in the On Current Event Procedure John |
|
|
|
Aug 4 2004, 05:34 PM
Post
#4
|
|
|
New Member Posts: 12 From: Missouri |
Thanks, that gave me enough info to get something working.
-Brett |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th June 2013 - 10:28 PM |