Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2019, 11:36 PM
matapagi2019 matapagi2019 is offline change the image by clicking Windows XP change the image by clicking Office 2007
Novice
change the image by clicking
 
Join Date: Mar 2019
Posts: 12
matapagi2019 is on a distinguished road
Default change the image by clicking

I want to replace userform lebel1 picture ("image_1.bmp") into ("image_2.bmp") after clicking once, and returning it again to ("image_1.bmp") after the second click.
But the following code does not change it.
Is there a solution for this?



Code:
Private Sub UserForm_Initialize()
    Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
End Sub

Private Sub CommandButton1_Click()
    If Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp") Then
        Label1.Picture = LoadPicture("D:\My Pictures\Image_2.bmp")
    Else
    End If
End Sub
For all help, thanks a lot.
Reply With Quote
  #2  
Old 03-23-2019, 01:35 AM
gmayor's Avatar
gmayor gmayor is offline change the image by clicking Windows 10 change the image by clicking Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You cannot get the image name that way, so you need to set a value that you can read from the command button whenever the image changes. You could use a hidden check box or a hidden label or use the tag property of the userform e.g.
Code:
Private Sub UserForm_Initialize()
    Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
    Label2.Caption = "Image1"
    Label2.Visible = False
    'Tag = "Image1"
End Sub

Private Sub CommandButton1_Click()
    If Label2.Caption = "Image1" Then
        'If Tag = "Image1" Then
        Label1.Picture = LoadPicture("D:\My Pictures\Image_2.bmp")
        Label2.Caption = "Image2"
        'Tag = "Image2"
    Else
        Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
        Label2.Caption = "Image1"
        'Tag = "Image1"
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 03-23-2019, 01:46 AM
gmayor's Avatar
gmayor gmayor is offline change the image by clicking Windows 10 change the image by clicking Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

On further reflection, you can use the same label e.g.
Code:
Private Sub UserForm_Initialize()
    Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
    Label1.Caption = "Image1"
    Label1.ForeColor = Label1.BackColor
End Sub

Private Sub CommandButton1_Click()
    If Label1.Caption = "Image1" Then
        Label1.Picture = LoadPicture("D:\My Pictures\Image_2.bmp")
        Label1.Caption = "Image2"
    Else
        Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
        Label1.Caption = "Image1"
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 03-23-2019, 03:23 AM
matapagi2019 matapagi2019 is offline change the image by clicking Windows XP change the image by clicking Office 2007
Novice
change the image by clicking
 
Join Date: Mar 2019
Posts: 12
matapagi2019 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You cannot get the image name that way, so you need to set a value that you can read from the command button whenever the image changes. You could use a hidden check box or a hidden label or use the tag property of the userform e.g.
Code:
Private Sub UserForm_Initialize()
    Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
    Label2.Caption = "Image1"
    Label2.Visible = False
    'Tag = "Image1"
End Sub

Private Sub CommandButton1_Click()
    If Label2.Caption = "Image1" Then
        'If Tag = "Image1" Then
        Label1.Picture = LoadPicture("D:\My Pictures\Image_2.bmp")
        Label2.Caption = "Image2"
        'Tag = "Image2"
    Else
        Label1.Picture = LoadPicture("D:\My Pictures\Image_1.bmp")
        Label2.Caption = "Image1"
        'Tag = "Image1"
    End If
End Sub
From your explanation, it makes perfect sense to me.
And I'm sure it will work well.
So, thank you very much for your help.
And I think the problem has been solved.

regards.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
change the image by clicking Change the image shown on my custom templates Sanwitte Word 3 03-20-2018 02:55 AM
change the image by clicking How to change original image sizes in Word menander Word VBA 6 03-05-2017 01:58 PM
activating a video after clicking on image jansmits PowerPoint 0 10-24-2013 10:17 AM
Clicking a picture to go to MSpaint? SharpTJ Word 0 03-13-2013 06:50 PM
Change object properties by clicking PopOnTheAir PowerPoint 7 03-16-2012 02:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft