Access form - changing and saving a record's background colour on button click

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bettyboo
    New Member
    • Aug 2008
    • 8

    Access form - changing and saving a record's background colour on button click

    Hi

    I'm new to the forum and also a VERY new user of Access to develop databases. I'm building a DB for a driving instructor acquaintance, and he wants a button on the pupil data entry form which he can click to flag a pupil as "Do Not Rebook" (i.e. if they're a non-payer or something). Upon clicking the button, he wants a value to be recorded in the appropriate field in the table (so we can report on it later) and he also wants the background of the entire record to turn red.

    i've created the toggle button on the form and when I click it, it records a value in the table to which the form is bound (the data type is set to on/off). So far so good. I then browsed this forum and managed to find some code which i adapted (probably very badly!!) to make the background colour of the form change to red at the time the button is clicked. However, what happens when I click is that the background colour is then changed on ALL the records in the form, rather than just the one I'm interested in. It also doesn't remember the formatting if I exit and go back into the form. This is important as he wants an instant visual reminder not to rebook certain individuals.

    Is it possible to restrict the background colour change to just one record, and to get Access to remember this for next time?

    I've posted the code I've got so far below plus some info on the field names/form name. I really am a total novice so I hope I've put enough info - any help much appreciated!

    Thx
    =:o*

    Code below is attached to On Click Event Procedure of a toggle button bound to DNR field in t_Pupils. Button itself is on form f_Pupils, bound to t_Pupils

    Code:
    Private Sub DNR_Click()
    
     If Me.DNR = -1 Then
      Me.Section(acDetail).BackColor = vbRed
    Else
      Me.Section(acDetail).BackColor = 16777215
    End If
    
    End Sub
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    If this is a Single View Form, i.e. if you can only view one record at a time, you simply need to palace the same code in the Form_Current event.

    Welcome to Bytes!

    Linq ;0)>

    Comment

    • bettyboo
      New Member
      • Aug 2008
      • 8

      #3
      Crumbs, that was quick! I will give it a go this evening and let you know how I get on. Thank you!!

      =;o*

      Comment

      • bettyboo
        New Member
        • Aug 2008
        • 8

        #4
        All sorted, works perfectly! Thank you!!

        :)

        Comment

        Working...