Control Object properties using conditional statement?

123dstreet

Registered User.
Local time
Yesterday, 18:40
Joined
Apr 14, 2010
Messages
122
Hi Everyone! I am just wondering if it is possible to create a conditional statement either in VBA or the expression builder, to control the visibility of an image on a report. Basically if text187 = "Dan" then I want the image visible. If text187 = "JOHN" then I want the image invisible. If anybody can help me out that would be great!

Thanks a lot!
Dan
 
Yes you can it might look something like;
Code:
    If TextBoxName.Value = "Open" Then
        Image9.Visible = True
        Image10.Visible = False
    ElseIf TextBoxName.Value = "closed" Then
        Image9.Visible = False
        Image10.Visible = True
    Else
        Image9.Visible = False
        Image10.Visible = False
    End If
There is a discussion here on the subject using a combo box to change hide/show images
 
Last edited:
Hi, I have tried to play around with this code, but nothing seems to be working for me. I am also trying to use vba to show/hide a control on a form. this is the code I am using:

Private Sub Combo223_AfterUpdate(Cancel As Integer)
If [Status] = "Inventory Removal" Then
'Show Inventory Removal Options'
[Combo316].Enabled = True
Else
'This is not an Inventory Removal'
[Combo316].Enabled = False
End If
End Sub

*[status] is Combo223..
*it does not seem to be working. It gives me this error message when I switch from design to form view: "Procedure declaration does not match description of event or procedure having the same name". Could anybody help me understand this?

Thank you
 
Your code should probably look like;
Code:
Private Sub Combo223_AfterUpdate(Cancel As Integer)
If Me.Combo223 = "Inventory Removal" Then
     [COLOR="SeaGreen"]'Show Inventory Removal Options'[/COLOR]
     Me.Combo316.Enabled = True
Else
    [COLOR="SeaGreen"] 'This is not an Inventory Removal'[/COLOR]
     Me.Combo316.Enabled = False
End If
End Sub

You need to refer to your controls by the name that Access knows them by, in this case Combo223 rather than the Label that you have given it Status, unless of course you change the name, which you have not done as your sub is automatically name Private Sub Combo223_AfterUpdate

You say you want to hide the combo but you are using it's Enabled property, this property will not hide the combo it will only Disable it on False so that it is grey out. Try the Visible Property.

Additionally you are testing for a text string "Inventory Removal" in your Combo223 this will only work if this is the data that is held in the bound column {usually the first column Column(0)}.
 
Thanks for your help, I played around a bit and found that this code worked perfectly for what I need:

Private Sub Combo223_Change()
If [Status] = "Inventory Removal" Then
'show this picture'
Image318.Visible = True
Combo316.Visible = True
Else
'hide this picture'
Image318.Visible = False
Combo316.Visible = False
End If
If [Status] = "ProForma" Then
'show proforma stuff'
Combo305.Visible = True
Else
'don't show proforma'
Combo305.Visible = False
End If
End Sub


I'm not sure why, even though the combo box is referred to as combo223, that using [status] still works.
 

Users who are viewing this thread

Back
Top Bottom