Graphics in a form (show/hide) (1 Viewer)

Dragonchaser

Registered User.
Local time
Yesterday, 18:09
Joined
May 15, 2007
Messages
31
Hey AP.uk

I've got Form with some drawings on it and I'd like it change depending on what the user has entered in certain fields on the same form.
For Example: when the user selects a certain type of item in the "Item1" field, I'd like the graphic to change (or another one appear) in the form. Basically an "If this is true, show this picture" type thing.
I've been trying a few things to make this happen, but to no avail... :(
Any incite anyone could give would be most appreciated.

Truly,

Dragonchaser
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 17:09
Joined
Dec 21, 2005
Messages
1,583
in the after update event of your item1 control put something like

If Me.cmboItem1 = "x" then
Me.Image54.Visible= True
Else
Me.Image54.Visible=False
End if

Where cmboItem1 is a combo box named 'cmboItem1' bound to your Item1 field, and Image54 is the name of the image control bound to your image. If your combo stores a number instead of text, change the condition from '="x" ' to '= 7' (for example), or for a date it would be '= #1/1/2007# '
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 17:09
Joined
Dec 21, 2005
Messages
1,583
You may also want to place the same code in the on-current event of the form so that the test occurs when you change records as well. You could also use a select case statement if you wish to test for more than one value that would generate different combinations of images.

e.g.,

Select case Me.cmboItem1
Case 1
Me.Image54.Visible = True
Me.Image55.Visible= True
Me.Image55.Visible= False
Case 2
Me.Image54.Visible = False
Me.Image55.Visible= True
Me.Image55.Visible= True
Case 3
Me.Image54.Visible = True
Me.Image55.Visible= True
Me.Image55.Visible= True
Case Else
Me.Image54.Visible = False
Me.Image55.Visible= False
Me.Image55.Visible= False
End Select
 

Dom DXecutioner

AWF VIP
Local time
Yesterday, 17:09
Joined
Jun 25, 2007
Messages
57
hi,

another way is to use only one image control... setup a folder where the images (bitmaps) will be stored and change the image picture property accordingly, this may help with performance.

sample code:

Code:
Private Sub theComboBox_AfterUpdate()
Dim strPicture As String
    [COLOR="SeaGreen"]'// open form ref[/COLOR]
    With Me
        [COLOR="seagreen"]'// test for valid selection[/COLOR]
        If Not IsNull(.theComboBox) Then
            [COLOR="seagreen"]'// select image based on combo value[/COLOR]
            Select Case .theComboBox
                Case Item1
                    strPicture = theImageFile1
                Case Item2
                    strPicture = theImageFile2
                Case Item3
                    strPicture = theImageFile3
                Case Item4
                    strPicture = theImageFile4
            End Select
        End If
        [COLOR="seagreen"]'// apply new image[/COLOR]
        .theImage.Picture = strPicture
    End With
End Sub

if the combobox value is a list from lookup table (dictionary), you could add an additional field such as ImagePath, then you could shorten your code...

Code:
Private Sub theComboBox_AfterUpdate()
Dim strPicture As String
    [COLOR="SeaGreen"]'// open form ref[/COLOR]
    With Me
        [COLOR="seagreen"]'// test for valid selection[/COLOR]
        If Not IsNull(.theComboBox) Then
        [COLOR="seagreen"]'// get the picture path in hidden column[/COLOR]
        strPicture = .theComboBox.Column(2)
        [COLOR="seagreen"]'// apply new image[/COLOR]
        .theImage.Picture = strPicture
    End With
End Sub
 

Dragonchaser

Registered User.
Local time
Yesterday, 18:09
Joined
May 15, 2007
Messages
31
Thanks Craig & DX!
You've saved me hours of syntax searching. :)
One more quick one.
Can Access store a folder of image files "in" the actual database? The same webpages lookup img files or something?
The Form keeps looking for the files on the hard drive. Which of course won't work when the client uses it on his computer.

Cheers,

Dragonchaser
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 17:09
Joined
Dec 21, 2005
Messages
1,583
Usually it's a bad idea to store image files in Access because they bloat the file size horribly and kill your app.

One way to avoid the issue of folder location is to always have your folder of photos saved in the same folder as the db. Then your path to the photofolder will be obtainable by using something like

Dim mypath as string

MYPATH = CurrentProject.Path & "\PHOTOFOLDERNAME\"
 

Dragonchaser

Registered User.
Local time
Yesterday, 18:09
Joined
May 15, 2007
Messages
31
Thanks again Craig.
But say the images are only "17x79" and less than 1kb ;) . Can you still store them in the database?
 

CraigDolphin

GrumpyOldMan in Training
Local time
Yesterday, 17:09
Joined
Dec 21, 2005
Messages
1,583
Just use the wizard to place the image you want on the form and make sure that you choose 'embedded' as the picture type (Properties>format tab).
 

Dragonchaser

Registered User.
Local time
Yesterday, 18:09
Joined
May 15, 2007
Messages
31
:eek: heh, I knew that. :eek:
Thanks for all your help Craig & DX.
 

Dragonchaser

Registered User.
Local time
Yesterday, 18:09
Joined
May 15, 2007
Messages
31
Over the weekend I added all the images and they all work properly, but of course I figured the images would work the same way in a report...There's no "after update" events in these report controls I guess no one's enter data here. So how would I have the images remain visible/invisible in the report just as they are in the form? :confused:
Whenever I print a record from the report it has all the images visible regardless of what is in the corresponding field.
All the controls and images in the report are the same as the form except for cosmetics. (i.e. forecolor and such)
Maybe I just wrote myself into a corner?
Is there a simple way to do this now, or should I remove the images and start again? :(
Any info anyone can lay on me would be more than helpful.

Thanks again,

Dragonchaser
 

Dom DXecutioner

AWF VIP
Local time
Yesterday, 17:09
Joined
Jun 25, 2007
Messages
57
you could potentially place the code in the [On Format] event of the report to trigger appropriate routine to change the image as necessary. Try searching the forum for things like IMAGES AND REPORTS.
 

Users who are viewing this thread

Top Bottom