Colouring a form field based on another field's content

andymac

Registered User.
Local time
Today, 23:45
Joined
Jun 2, 2013
Messages
36
Hello,

I need a little help doing something on access which to me seems very complicated!

I am making a very simple 'registration' database for a children's event in a couple of weeks.

I the table/form there is a checkbox field called 'consent' which, if checked, indicates that a child can leave the event without parental consent.

There is a report printed on each child (a registration page which the leaders get a copy of). I would like on this report a 'red box' to appear if the child cannot leave without permission (i.e. the consent box is not checked). I would also like this 'red box' to appear on the form.

I had thought of doing it this way - but I'm not sure if it's the best, or if it's possible:

Have a field in my table called 'consentindicator'. When the 'consent' box is checked, there is a period ('.') placed into the 'consentindicator' field. It is set to turn red when a period is present. That way, when the consent box is checked, a get a red 'box'.

Does this make sense? And/or is there a better way?

Thanks,

Andy
 
You don't need an extra field, you can use the value of the checkbox 'consent'.
Place a box on the form, call it RedBox.
Place the following code in the checkbox 'consent' after update event, and the form's current event.
Code:
Private Sub Consent_AfterUpdate()
  If Me.consent Then
    Me.RedBox.Visible = False
  Else
    Me.RedBox.Visible = True
  End If
End Sub

Private Sub Form_Current()
  If Me.consent Then
    Me.RedBox.Visible = False
  Else
    Me.RedBox.Visible = True
  End If
End Sub
And for the report, place a box on the report, call it RedBox.
Place the following code in the report's detail on format event.
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
  If Me.consent Then
    Me.RedBox.Visible = False
  Else
    Me.RedBox.Visible = True
  End If
End Sub
 
Code:
If Me.consent Then
    Me.RedBox.Visible = False
  Else
    Me.RedBox.Visible = True
  End If

This code can be simplified to one line.

Code:
Me.RedBox.Visible = Not Me.Consent
 
Hi,

Thanks for your help - I got it working perfectly on the form - but for some reason it won't work on the report?

Any suggestions?

Thanks

Andrew
 
Andrew, which event have you placed the code to do this color change?
 
I have it in "details" and "format" if that makes sense.

Andrew
 
Hi just wondered if anyone had thought any more on my dilemma? Do you want me to upload the DB?
 
If you don't have got it, then upload the database, (zip it if you not have post 10 post yet).
 
If this is not a Continuous Form you can put on the Main form on current the change of From colour, I use images to do the tranfromation. I also set the Unbound field so the change only occurs on when the conditions change:

Code:
        If .[Orig Stock Status] = "P" And .[StockStatus] <> "P" Then
            .[Label_Header].Picture = "C:\Databases\Livery\Forms\Header_Originals_Purchase.png"
            .Picture = "C:\Databases\Livery\Background\Originals_Purchase.jpg"
            .Header_Background.Picture = "C:\Databases\Livery\Header\Originals_Purchase.png"
            .[StockStatus] = "P"
        ElseIf .[Orig Stock Status] = "H" And .[StockStatus] <> "H" Then
            .[Label_Header].Picture = "C:\Databases\Livery\Forms\Header_Originals_History.png"
            .Picture = "C:\Databases\Livery\Background\Originals_History.jpg"
            .Header_Background.Picture = "C:\Databases\Livery\Header\Originals_History.png"
            .[StockStatus] = "H"
        ElseIf .[Orig Stock Status] = "C" And .[StockStatus] <> "C" Then
            .[Label_Header].Picture = "C:\Databases\Livery\Forms\Header_Originals.png"
            .Picture = "C:\Databases\Livery\Background\Originals.jpg"
            .Header_Background.Picture = "C:\Databases\Livery\Header\Originals.png"
            .[StockStatus] = "C"
        End If
    End With
End Function

Simon
 
The form in question is 'badge'
Thanks
You mean the report do you not?
You've to choose "Print Preview", then it works, (see attached picture)!
 

Attachments

  • Summer.jpg
    Summer.jpg
    52.4 KB · Views: 100
You are absolutely correct - I didn't realise access differed between 'report view' and 'print preview' - I feel like such an idiot!

Apologies for squandering all your time!

Andrew
 
You are absolutely correct - I didn't realise access differed between 'report view' and 'print preview' - I feel like such an idiot!

Apologies for squandering all your time!

Andrew
No problem - if you one time have spent a lot of time on a "silly" thing as 'report view' and 'print preview', you'll never forget it. :)
 

Users who are viewing this thread

Back
Top Bottom