Button visible/invisible in a Continuous Form

I'd forgotten this - so simple & effective - have just used it for a web article
Thanks again @Saphirah
 
Last edited:
I didn't know about this ability with buttons in a continuous form. Amazingly, this also works to change the button captions as well. I'm blown away.

1705442197449.png
 
I've now taken this idea one stage further. As well as selectively hiding buttons in a continuous form, I can also selectively hide other controls (textboxes, checkboxes, combos). For example, in the screenshots below, the CAT field is hidden when its value is "B" and the checkbox is hidden when it is false

1705663376983.png


This approach potentially has many uses for continuous forms
 
I've now taken this idea one stage further. As well as selectively hiding buttons in a continuous form, I can also selectively hide other controls (textboxes, checkboxes, combos). For example, in the screenshots below, the CAT field is hidden when its value is "B" and the checkbox is hidden when it is false

View attachment 112079

This approach potentially has many uses for continuous forms
Hello. Thank you for providing this and your web article above!
I am facing an issue where the buttons inside my continuous form become intransparent when I hover and/or click on a given button despite having set the button transparency to true.

This is my code:

Code:
Private Sub btnOpenFiles_Click()
    If Not Me.btnOpenFiles.Transparent Then
        MsgBox "Button event will be executed"
    End If
End Sub

Private Sub Detailbereich_Paint()
    If Nz(Me!files) <> "" Then
        Me.btnOpenFiles.Transparent = False
    Else
        Me.btnOpenFiles.Transparent = True
    End If
End Sub

It is behaving very strange when "Me!files" is Null or an empty string. The button for that record should be transparent in that case, as you can see from my code. However, when I hover over that transparent button it can often times be seen anyway. Sometimes it will stay visible, even after moving the cursor somewhere else. Sometimes the button event is also executed, even though the button should be transparent. I have not been able to find out any pattern of when this bug occurs. There are no other events defined for that button.
Do you have any ideas what could be the issue here?
Thank you very much!
 
That point is explained in my article Paint Me Transparent (isladogs.co.uk) as mentioned in post #21
The problem is that transparent buttons can still be clicked unless you also disable them when transparent

In the example, I used a locked checkbox with the button. Clicking the button makes the checkbox false
The Detail Paint event then makes the button transparent if the checkbox is false
As the checkbox is locked, the action can't be reversed

In your case, try

Code:
Private Sub Detailbereich_Paint()
    Me.btnOpenFiles.Transparent = Not Nz(Me!Files, "") = ""
End Sub

If that doesn't work, try adding a hidden locked checkbox to prevent the transparent button being clickable
 
Thank you for the reply!
I had already read the article but I feel like my problem is a little different.

If I understand correctly, in your example the button is made transparent after it is clicked (by setting the checkbox to true and making the button transparent in the detail paint event if the checkbox value is true).
In my case I want the button (or rather 2 buttons actually) to be only visible and clickable when the value "Me!files" for that record is not Null or empty.

I changed my code to this:
Code:
Private Sub Detailbereich_Paint()
    Me.btnViewFiles.Transparent = Nz(Me!dateien) = ""
    Me.btnOpenFiles.Transparent = Nz(Me!dateien) = ""
End Sub

Private Sub btnOpenFiles_Click()
    If Nz(Me!dateien) <> "" Then
        MsgBox "Executed"
    End If
End Sub

Private Sub btnViewFiles_Click()
    If Nz(Me!dateien) <> "" Then
        MsgBox "Executed"
    End If
End Sub

Initially the buttons are now only visible when the corresponding value of me!files is not Null or empty. This is now behaving as it should. Now the msgbox also only pops up when me!files is not Null or empty. This is also behaving as expected now.
However, there is one last issue that I cannot seem to resolve.

When hovering and/or clicking on the right button (btnViewFiles) it can often be seen, even though it should actually be transparent. This does not happen with the left button (btnOpenFiles).
That seems really odd to me, since I used the same code for both buttons so far. I also tried deleting and recreating that second button or to copy/paste the first button that is behaving correctly. The issue remains the same though.

To clarify my problem I attach some screenshots here:

After the form is loaded, both buttons are correctly shown only for the last record (which contains a value for me!files):
1708000753954.png


Now I move the cursor above the area on where the second button would be in the third record and I click. Then that button is suddenly seen (but the msgbox does not pop up):
1708000898030.png


Now I move the cursor further up to the first record. When hovering over the transparent buttons, they are now also suddenly seen:
1708001051495.png



The top right 3 buttons should not be visible in this example. After clicking either of these 3 buttons, they may or may not disappear again. This behavior does not occur for the left button, only for the right one.
As mentioned earlier, I have no other events other than "on click" defined for these buttons.

Do you have any idea what could be the problem here? Thank you :)
 
Thank you for the reply!
I had already read the article but I feel like my problem is a little different.

If I understand correctly, in your example the button is made transparent after it is clicked (by setting the checkbox to true and making the button transparent in the detail paint event if the checkbox value is true).
In my case I want the button (or rather 2 buttons actually) to be only visible and clickable when the value "Me!files" for that record is not Null or empty.

I changed my code to this:
Code:
Private Sub Detailbereich_Paint()
    Me.btnViewFiles.Transparent = Nz(Me!dateien) = ""
    Me.btnOpenFiles.Transparent = Nz(Me!dateien) = ""
End Sub

Private Sub btnOpenFiles_Click()
    If Nz(Me!dateien) <> "" Then
        MsgBox "Executed"
    End If
End Sub

Private Sub btnViewFiles_Click()
    If Nz(Me!dateien) <> "" Then
        MsgBox "Executed"
    End If
End Sub

Initially the buttons are now only visible when the corresponding value of me!files is not Null or empty. This is now behaving as it should. Now the msgbox also only pops up when me!files is not Null or empty. This is also behaving as expected now.
However, there is one last issue that I cannot seem to resolve.

When hovering and/or clicking on the right button (btnViewFiles) it can often be seen, even though it should actually be transparent. This does not happen with the left button (btnOpenFiles).
That seems really odd to me, since I used the same code for both buttons so far. I also tried deleting and recreating that second button or to copy/paste the first button that is behaving correctly. The issue remains the same though.

To clarify my problem I attach some screenshots here:

After the form is loaded, both buttons are correctly shown only for the last record (which contains a value for me!files):
View attachment 112574

Now I move the cursor above the area on where the second button would be in the third record and I click. Then that button is suddenly seen (but the msgbox does not pop up):
View attachment 112575

Now I move the cursor further up to the first record. When hovering over the transparent buttons, they are now also suddenly seen:
View attachment 112576


The top right 3 buttons should not be visible in this example. After clicking either of these 3 buttons, they may or may not disappear again. This behavior does not occur for the left button, only for the right one.
As mentioned earlier, I have no other events other than "on click" defined for these buttons.

Do you have any idea what could be the problem here? Thank you :)
Can you upload a cut down version of your database with this form for me to look at and see if I can fix it for you
 
Thank you for helping out.
I have provided a database file where the bug occurs. If you open the form "MainForm" you will see the form with 2 subforms. In the right subform there are the two buttons from my screenshots above. They should only be visible if the corresponding field is not empty.
The right button can often times be seen anyway, especially when clicked on or hovered over.

I was going to upload a video file as well where I demonstrate the bug. Unfortunately video files are not accepted for upload here.
 

Attachments

I zipped the video file where I show the bug. It is a little blurry, since I had to compress it, but I think you get the idea.
Cheers!
 

Attachments

Doesn't appear to do that for me?
 
Doesn't appear to do that for me?
That is strange. Did you see the video that I provided?
Did you try to click the transparent right buttons? They were not visible the entire time?

I also tried to repair and compress the database and the issue persisted.
I also created a new accdb file and imported all the forms, tables and modules into it that are related to that form. The issue was still the same though.

Could this have anything to do with my windows settings?
 
Yes, I watched the video and saw you clicking where your buttons were, then it would appear. I added a new file to a record and still I could only get the execute msg, evern when clicking where I know the buttons should be.
 
Sounds like it is behaving as it should in your environment. I don't really know what to do now.. Reinstall Ms Office? 😅

The strange thing is that I also tried creating a new database and form from scratch that is a little simpler than the file I provided. I only had the code in there that I posted a few posts ago. Also I had just one table and one form. In that accdb-file the bug did not occur anymore. I don't really know what to make out of all of this.
 
I can replicate the issue & have spent about half an hour trying to fix the problem with limited success
Attached is my version. You may still see some flickering but should no longer see transparent buttons reappear or be clickable.

I think there may be either corruption in the form or its an issue with the complex dataset used
If you can get it to work with a simplified version, I would do so
 

Attachments

I'd forgotten filtering & found it was worse after applying & removing a filter but better after saving.

UPDATE
Fixed it! Swop the two button positions so the view files button is on the left of the open files button!
The transparent button no longer appears. No idea why
 
I'd forgotten filtering & found it was worse after applying & removing a filter but better after saving.

UPDATE
Fixed it! Swop the two button positions so the view files button is on the left of the open files button!
The transparent button no longer appears. No idea why
Thank you for the effort! I switched the 2 button positions but first the issue was still there (the formerly right button would appear again). Then I changed the positions back to the original positions and now the bug seems gone 🤨
There is just some minor flickering when I click at the position where a transparent button is. The button can be seen for a fraction of a second. I think that is the flickering that you mentioned earlier? I can live with that as long as the original problem doesn't magically appear again 😅

The file that you provided in post #35 did not work for me either. The button that you put the magnifying glass icon on would show up for all the records when I hover over their positions. Just like in my initial bug.

I'd forgotten filtering & found it was worse after applying & removing a filter but better after saving.
I did not notice this in my case. What I did find however, is that when the entire form does not contain a record with a value for the "files" field, all the buttons will be hidden, as they're supposed to. They will also not show up, even when I click them.

Let's see if this bug will come back as I keep modifying this form. I hope not..
I am kind of curious though, how my provided and your modified form behave on other peoples systems and if they experience that same issue.

By the way, do the command buttons look like plain squares in design view for you as well? In form view they look like buttons but in design view just like this:
1708034756214.png

I had never seen this before. I don't know if that has anything to do with the original bug though.
 
Swopping buttons doesn't work in your original version but it did in mine
Try swopping the button positions in the version I uploaded in post #35
However, I'd still try to use a simpler solution to guarantee reliability.

Yes - the command buttons look like your screenshot on my machine.
That's because you set Transparent = Yes in the property sheet
 
Swopping buttons doesn't work in your original version but it did in mine
Try swopping the button positions in the version I uploaded in post #35
However, I'd still try to use a simpler solution to guarantee reliability.

Yes - the command buttons look like your screenshot on my machine.
That's because you set Transparent = Yes in the property sheet
You're right, when I switched the buttons in the file from post #35 the bug was gone. I was even able to switch the positions back to the original and the bug did not come back.

What do you mean by a simpler solution? Are you refering to showing/hiding multiple buttons in the continuous form or are you refering to how the sql-string of the query is concatenated? Or something completely different?

I have considered to use textboxes instead of buttons and use conditional formatting to change the textbox background color to the same as the detail section background color in order to make the textbox "invisible". I would prefer to use actual command buttons though to ensure a consistent formatting with other buttons and to be able to have icons on the buttons.

Other than that I am not really sure how I could simplify the form without removing some of the functionality that I would like my form to include.
Thank you for sharing your thoughts :)
 
What do you mean by a simpler solution?

I wrote that comment because you had previously written:
Let's see if this bug will come back as I keep modifying this form. I hope not..

As I said, I've no idea why swopping the buttons worked. Nor why another similar form worked without issue for you when this one hadn't.
Its quite possible that additional complexity will break your form again. Do bear in mind that although this can work well, it isn't a standard approach

You may well be able to achieve similar results in other ways.
 

Users who are viewing this thread

Back
Top Bottom