We help IT Professionals succeed at work.

How can i programmatically make an image visible based on value of text box?

linbayzak
linbayzak asked
on
310 Views
Last Modified: 2013-11-28
Hi Experts,

i have a form that is a subform of another form, it is never loaded separately from the main form.  I have written some code to make an image of a red flag visible if the value of the text box (txtCategory) is "High", but i'm not getting any results.  I have this code in the load event of the subform.  Why is this not working?

Thanks.

Private Sub Form_Load()
 
    If Me.txtCategory.Value = "High" Then
        Me.imgRedFlag.Visible = True
    End If
    
    If Me.txtCategory.Value = 3 Then
        Me.imgRedFlag.Visible = True
    End If
    
End Sub

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:
Perhaps txtCategory's value is not "High" or 3 when the form opens - it can't he both.

Is txtCategory and imgRedFlag in the subform?

Try posting your database so I and others can look at it. To remove private information and reduce the size of the database, do this:
1. Make a copy of your db.
2. If using Access 2007, convert the database to an mdb format.
3. Remove all tables, queries, forms, pages and reports that have nothing to do with the problem.
4. Delete all but 6-12 records in the remaining tables - use shift / Mouse select to select huge blocks of records, then delete.
5. Import all linked tables so that everything is in the one database
6. Remove any passwords.
7. Disable all Startup options.
8. Compact and repair
9. Move the database to a different folder to make sure it still runs showing the problem
10. Post explicit steps to recreate the issue.
11. Zip (optional) and attach to a message.
... Again, test the DB before posting to make sure that we can open the DB and easily see the issue.

Author

Commented:
Yes, txtCategory and imgRedFlag are both in the subform.  Sure, i'll post it. Thanks :-)
PrenatalTreatment.mdb
CERTIFIED EXPERT

Commented:
So I don't have to search the entire database, on what form is txtCategory and imgRedFlag?
CERTIFIED EXPERT

Commented:
frmnotes is a continuous form.  Realize the continuous form has only one of each control in its detail section. That one control is repeated as many times as needed for as many records there are in the report's record source property. But if you try to fill or modify an unbound control by another means, there is only one and that one control will display the same value in the control repeated for each record . So instead of the code you are using, you need to use conditional formatting ( format, conditional formatting.) Setting a control to visible or not vi sable is not an option with conditional formation so you might want to consider changing the txtCategory background color when it is equal to "High" or 3.

Author

Commented:
sorry, it's on frmNotes
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
good, cause i tried it and it didn't work for me.  i'll take a look, thanks

Author

Commented:
i don't see the changes, sorry, i looked in frmNotes
CERTIFIED EXPERT

Commented:
Click on txtCategory in design mode. Then select Format, conditional format.

Author

Commented:
Very good, experts.  This will do, thanks for all your help :-)

Laura
CERTIFIED EXPERT

Commented:
You're welcome.  Glad to help and thank you very much for the points with "A" grade!

Happy computing!

Nelson

Author

Commented:
Thanks, as you can probably tell, i'm pretty new :-) Have a great afternoon!!!!!!!!!!

Commented:
Good luck, Laura :)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.