Solved Flickering when scrolling records. (1 Viewer)

Local time
Today, 06:44
Joined
Feb 28, 2023
Messages
628
I'm going to post this as solved, but I used an odd method and perhaps not the best one ...

I'm adding an audit trail to events on a form: https://www.access-programmers.co.u...update-of-a-field.329588/page-10#post-1909410

I have a command button that displays the audit results, but many of the older records will not have any audit results and never will have any audit results.

So we wanted the button to only be visible if there were results to display.

Previously I could scroll through the records without any issues - I saw the data in the textbox fields change, but nothing else.

I added this code in the forms Form_Current() Event:
Code:
' Hide History Button if no History Records:
'Application.Echo False
If DCount("[REFERENCE]", "qryAuditLogTCTO") = 0 Then
    Me.btnHistory.Visible = False
Else
    Me.btnHistory.Visible = True
End If
'Application.Echo True

It works fine and does what was intended, but when I scroll through the records, the btnHistory is flashing b/c the code has to decide whether to show it or not. And it doesn't matter if the History button is visible by default or not visible by default in the form properties.

The Application.Echo suggestion came from https://www.access-programmers.co.u...n-flashes-flickers-and-form-refreshes.211223/ if I uncomment those lines, the btnHistory doesn't flash at all, but the entire form seems to re-paint when I scroll to a new record.

What seems to work is this:
Code:
If DCount("[REFERENCE]", "qryAuditLog") = 0 Then
    If Me.btnHistory.Visible = True Then Me.btnHistory.Visible = False
Else
    If Me.btnHistory.Visible = False Then Me.btnHistory.Visible = True
End If

With this code, the form only has to show/hide the button if it's value is different from it's current value.

There is still a very minor delay before the button appears, but it is negligible.

Hope this helps others and please reply if anyone knows a better solution!!!
 

CJ_London

Super Moderator
Staff member
Local time
Today, 11:44
Joined
Feb 19, 2013
Messages
16,612
Rather that using a button - use a text box with conditional formatting

would also be better to use a sub query in your form recordsource rather than dcount in your form

simpler code if you don’t want to go that route


Me.btnHistory.Visible =DCount("[REFERENCE]", "qryAuditLog")<> 0
 
Last edited:
Local time
Today, 06:44
Joined
Feb 28, 2023
Messages
628
I prefer the look of the button to the text box, although I suspect the text box could possibly be made to look the same.

I'm not sure how to use the sub query in the form record source. This is not the record source for the form. The button on the form is visible if a separate query has records in it.

I got the Dcount idea mainly from: https://www.devhut.net/ms-access-vba-get-record-count/

What would be faster, but I didn't know how to do it - the query will never have more than about 20 records, but I don't really care how many records it has, I just need to know if it contains at least one.
 
Last edited:

CJ_London

Super Moderator
Staff member
Local time
Today, 11:44
Joined
Feb 19, 2013
Messages
16,612
Thought you were talking about a continuous form.

sql will be faster than vba but perhaps not relevant in this case.
 
Local time
Today, 06:44
Joined
Feb 28, 2023
Messages
628
Different issues - I have another thread about issues with a datasheet view in a pop-up form. Sorry for the confusion.
 

Users who are viewing this thread

Top Bottom