• Different background on a particular field in a form

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Different background on a particular field in a form

    Author
    Topic
    #459251

    Hi to you all,

    I have a field for vehicle licence expiry dates, I would like to be pre warned 30 days or so BEFORE the persons driving licence expires by making the field background turn red…

    is this possible..

    kind regards

    Steve Gulliver
    Southampton UK

    Viewing 3 reply threads
    Author
    Replies
    • #1157478

      I have a field for vehicle licence expiry dates, I would like to be pre warned 30 days or so BEFORE the persons driving licence expires by making the field background turn red…

      is this possible..

      Yes, assuming that we’re talking about a form as opposed to looking at the raw table.

      One way to do this is to use Access VBA’s OnCurrent event, which will trigger whenever a new record is loaded into the form.

      (air code)
      [codebox]If [LicenceExpiry]-30 <= Date Then
      LicenceExpiry.BackStyle = 1
      LicenceExpiry.BackColor = rgb (255,0,0)
      Else
      LicenceExpiry.BackStyle = 0 ' sets it to transparent. change it to white (or whatever else) if you prefer by chaning the BackColor property instead
      End If[/codebox]

      But probably the easier way is to use conditional formatting. The expression to use is similar to the above: [LicenceExpiry]-30<=Date.

    • #1157482

      Conditional Formatting is another situation where the Date function needs its brackets.

      [LicenceExpiry]]<Date()+30

    • #1157525

      Hi Guys

      thanks very much for your help, I have inserted the routine you suggested, I think it’s almost there, however I think I must be doing something slightly wrong? When I put in this command it changes ALL my existing drivers on the database some 400 or so… Wonder if you chaps have any other ideas…

      kind regards

      Steve Gulliver
      Southampton UK

      • #1157564

        Do you have a continuous form? A continuous form essentially contains a single set of controls – if you change the background color of a control, it will change in all displayed records.
        Conditional formatting, however, works at the individual record level, so it’s more suitable for your purpose.

        • #1157646

          However, conditional formatting will change only the record effected in a continuous form, which is probably what is wanted.

    • #1157678

      Thank you very much indeed gentleman, I have used the formatting option. And it works fine..

      kind regards

      Steve Gulliver
      Southampton UK

    Viewing 3 reply threads
    Reply To: Different background on a particular field in a form

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: