Code for pictures on a form

mbono1

New Member
Joined
Mar 30, 2006
Messages
19
Hi all,

I battled with something very very basic. I am trying to change a picture, when a certain field matches a certain criteria. But i can't seem to get it to update.

I have the following code which I have simplified.

If [JV].Value = "One" Then

[OLEUnbound10].Visible = True
[OLEUnbound118].Visible = False
[OLEUnbound11].Visible = False

If [JV].Value = "Two" Then

[OLEUnbound10].Visible = False
[OLEUnbound118].Visible = True
[OLEUnbound11].Visible = False

If [JV].Value = "Three" Then

[OLEUnbound10].Visible = False
[OLEUnbound118].Visible = False
[OLEUnbound11].Visible = True

End If
End If
End If

I want these pictures to update when the form is loaded, as well as when the field is changed.

Any idea's?

Anybodys help would be appreciated.

thanks

mbono1
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi

It looks like you have nested your if statements. Rather than use 3 'if' statements and 3 'end if' statements, change the 2nd and 3rd 'if' statements to 'elseif' and delete 2 of the 3 'end if' statements.

Andrew
 
Upvote 0
If you have several sets of options, a Select Case statement is easier to maintain. I would create a separate routine on the form's code module, then reference that in the form's Current event and the field's AfeterUpdate event:
Code:
Private Sub ShowImages()
    Select Case [JV].Value
    Case "One"
        [OLEUnbound10].Visible = True
        [OLEUnbound118].Visible = False
        [OLEUnbound11].Visible = False
    Case "Two"
        [OLEUnbound10].Visible = False
        [OLEUnbound118].Visible = True
        [OLEUnbound11].Visible = False
    Case "Three"
        [OLEUnbound10].Visible = False
        [OLEUnbound118].Visible = False
        [OLEUnbound11].Visible = True
    End Select
End Sub

Private Sub Form_Current()
    ShowImages
End Sub

Private Sub JV_AfterUpdate()
    ShowImages
End Sub

To make sure that the events fire correctly, go to the Properties for the form, select the Events tab, and double-click the Current line so you see Event Procedure. Do the same for the After Update event of the JV control.

Denis
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,386
Members
448,891
Latest member
tpierce

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top