By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

Display image if a condition is met

P: 1
Hi,
I have a form in access 2007. I want to use IIf to display an image if a condition is met. I used the following IIF function in my form.
Expand|Select|Wrap|Line Numbers
  1. =IIf([SLDueAmount]="0","(D:\My accounts database 2007\images-2 "," D:\My accounts database 2007\images-1.gpj")
- The images i am trying to use are stored in the same folder of my database .
- I also tried to locate the images in my form but in both cases i get a text instead of the image.
Please advise
Regards
Jan 18 '14 #1
Share this Question
Share on Google+
1 Reply


ADezii
Expert 5K+
P: 8,634
Before we can proceed, I must make a couple of Assumptions beforehand:
  1. The 2 Graphic Files you describe reside in the 'same' Folder as your Database.
  2. The Container for these Graphic Files will be an Image Control named Image1 which is not Bound but used for display purposes only.
  3. There is a Bound Control (Text Box) on your Form named [SLDueAmount]. The Control Source for [SLDueAmount] is a Field of the same Name, with a Currency Data Type, in the Record Source of the Form.
  4. You also have the capability of adding New Records from this Form.
  5. The above being said, the following Code, placed in the Current() Event of your Form, will do the trick:
    Expand|Select|Wrap|Line Numbers
    1. Private Sub Form_Current()
    2. With Me
    3.   If .NewRecord Then
    4.     ![Image1].Picture = ""
    5.       Exit Sub
    6.   End If
    7. End With
    8.  
    9. With Me
    10.   If ![SLDueAmount] = 0 Then
    11.     ![Image1].Picture = CurrentProject.Path & "\Images-2.jpg"
    12.   Else
    13.     ![Image1].Picture = CurrentProject.Path & "\Images-1.jpg"
    14.   End If
    15. End With
    16. End Sub
Jan 18 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.