Conditional Formatting a Datasheet Form (1 Viewer)

luconsta

New member
Local time
Today, 18:21
Joined
Jan 5, 2017
Messages
8
Hello Everyone,

I have a problem formatting a form displayed as DataSheet. I am using a code provided by WayneRyan in another thread (Conditional Format Based on Previous and Current Record)(unfortunately I am not allowed to post with links yet) that toggle color based on an ID, in my case Order number.

Initially it seems is working ok, but in some cases, after scrolling the form or refreshing it, will break somehow and will color orders incomplete or will "blend" the color to the next order.

Can someone explain what can cause this?

I have attached a sample database and a picture that will show the "defective" formatting.

Thank you!
Lucian
 

Attachments

  • toggle_luconsta.accdb
    800 KB · Views: 80
  • Toggle_Error.png
    Toggle_Error.png
    8.9 KB · Views: 91

CJ_London

Super Moderator
Staff member
Local time
Today, 16:21
Joined
Feb 19, 2013
Messages
16,746
interesting one - the only way I could get the formatting to not work as intended is to move the mouse over the form records - say starting around 7/8, but doesn't really matter where) before the conditional formatting kicks in. The form seems to start to format these first rather than the ones at the top, although it doesn't always make a difference.

You can see similar behaviour if you scroll down the form - the conditional formatting does not kick in until the control is visible and the scroll bar released.

So I suspect it is something to do with access form visibility events which so far as I am aware there is no control as such. I tried playing around with disabling/enabling controls, hiding the form until current event, ensuring the query was sorted, continuous form but not able to get round the problem - which seems to be created when the mouse is moved over the form before or during the conditional formatting being applied.

Interestingly, I applied the getfieldcolor function to the query so it was 'populated' there instead - and inspecting it the values were correctly returned as 0 or -1. But having modified the conditional formatting to work off this column instead of the function, the same problem remained.

Regret I don't have a solution other than investigating disabling the mouse for a second or two whilst the conditional formatting does its stuff.
 

luconsta

New member
Local time
Today, 18:21
Joined
Jan 5, 2017
Messages
8
Thank you CJ_London for the answer and also for the hint - putting the function to set one colum of the query should be more reliable.

But in this case how can I could create a function that will have to return only 2 values, let's say 0 & 1 but making sure that on the first record in query will put 0 and then continue to "switch value" only when the OrderId will change.

I remember that WayneRyan warned that his "toggle sample" will switch the coloros so first record may some times be one color or the other after an refresh but if there is a way to start with 0 at first record maybe the color will remain.

So, is it possible to start counting at first record resulting something like this:

OrderID ColorID
1...........0
1...........0
2...........1
2...........1
3...........0
3...........0

Thanks,
Lucian
 

CJ_London

Super Moderator
Staff member
Local time
Today, 16:21
Joined
Feb 19, 2013
Messages
16,746
you use the same function in your query

Expr1:getformatcolor([ID])

and in your conditional formatting

Expression Is....[Expr1]=-1


to fix the starting color, try setting the public variables to 0 (or -1 if you want to start with the conditional color) in the form open event (don't have the db anymore so can't quite remember the names)
 

Users who are viewing this thread

Top Bottom