Results 1 to 14 of 14
  1. #1
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15

    How to toggle Image visibility "runtime"? On off? In a form?

    Hi.
    I want to achieve that if I press a picture in a form, then it will be visible, when pressing the same image again, then unvisible. This is also posted in https://www.accessforums.net/showthread.php?t=70061

    I suffer from Cervical Neck Prolapse and want to log my pains. I have created a lot of small images of different parts of the body. I have stacked all those pictures on top of each other. I can add an event "onclick" when clicking the picture - and then make that part of the body visible. But I am not able to disable the visibility when clicking the next time. I have searched and searched, but all searches comes up with "ToggleButton". I dont need a toggle button, but just an approach to how to achieve the following: Say image1 is my shoulder (in a form). When I click, the shoulder is visible. Next time I click the same image, I want it to be hidden. How do I achieve this? Tried this code, but it only sets it visible, then I cannot click again to go back. Thanx a lot in advance.


    Code:
    Private Sub Image1_Click()
    Me.Bilde2.Visible = (Not Me.Image1.Visible)
    End Sub
    Click image for larger version. 

Name:	Pain man hode.jpg 
Views:	13 
Size:	147.8 KB 
ID:	32360
    Kropp test.zip
    Last edited by Madmads; 01-25-2018 at 03:13 AM.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    I don't think you can change visibility if the control has focus ?
    Try moving the focus else where then setting visibility.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    I think so (I am not an expert). If you try to run the embedded file, you will see I am able to turn visibility ON on first click, but on second click, nothing happens? Best, Mads. (And thankyou)

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Sorry being very dense.
    As soon as it's not visible you can't click it again...

    Try this
    Code:
    Private Sub Bilde2_Click()
    
    
    
        If Me.Bilde2.BackStyle = 1 Then
            Me.Bilde2.BackStyle = 0
        Else
            Me.Bilde2.BackStyle = 1
        End If
    End Sub
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    Thx. Now I am able to update "real time", but this is only changing the background, not the visibility of the "Bilde2". When I run this, the background changes to white, hiding whats behind. Is it possible to use with the visibiliy property instead? Updating real time?

  6. #6
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    Tired this:
    Private Sub Bilde2_Click()
    If Me.Bilde2.Visible = False Then
    Me.Bilde2.Visible = True
    Else
    Me.Bilde2.Visible = False
    End If
    End Sub

    But it does not update ... As yours did (but it did not update the visibility in "runtime" (if that is the right name?). Thx for helping.

  7. #7
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    Should I use refresh? Or recalc or something? Thanx.

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,157
    Like I said that will only work once, as soon as you make it NOT visible it can't be clicked again, as it is no longer there.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  9. #9
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    Ok. Now I understand - that is the reason. I cannot click an invinsible object? Is there any workarounds? Hidden instead of visible or something like that?

  10. #10
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You could have a name for each image. This could be a button or an option group. When clicked, it makes all images invisible and the relevant one visible.

  11. #11
    Madmads is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    15
    Thx a lot. May i ask you to elaborate a little bit. I am a bit into coding, but not that experienced. How would this save me time? If you got time (and want to) I would be so grateful for a piece of sample code. Thx.

  12. #12
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    My advice wasn't about saving you time, not sure where that came from.

    Start with a common routine (change names as applicable).

    Private Sub MakeInvisible()
    Me!Image1.Visible=False
    Me!Image2.Visible=False
    .....
    End Sub

    Then, if you are using command buttons, for each button in its OnClick event:
    Call MakeInvisible
    Me!ImageX.Visible=True

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Another method of showing/hiding several controls at once is to make use of the controls' tag property.
    The easiest way to explain this is with an example that I posted a few months back
    https://www.access-programmers.co.uk...d.php?t=293439
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 05-28-2016, 07:35 AM
  2. Replies: 1
    Last Post: 09-07-2015, 08:00 AM
  3. Replies: 1
    Last Post: 09-03-2014, 03:27 AM
  4. Replies: 7
    Last Post: 11-08-2013, 08:28 PM
  5. Replies: 6
    Last Post: 10-17-2013, 03:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums