Page 1 of 2 12 LastLast
Results 1 to 15 of 29
  1. #1
    Nokoff is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    17

    Question Insert comment if checkbox is ticked

    Hi Guys, thank you for this wonderful community and the people that make it so, I am a first time poster but long time lurker.

    I am working on a database which will basically serve to be a massive Auditing Checklist. Lots of "Is this done" type yes/no questions to record, some with a comment.

    Brief Description: I have many child-forms on a tab-control, each with a different heading/category of things to check for. When someone visits a store, I would like them to record their findings in this form.

    Click image for larger version. 

Name:	Access Q1.png 
Views:	17 
Size:	32.3 KB 
ID:	21235

    In the above example, if the Floors are clean, no input is necessary. If the floors are not clean then the user ticks the checkbox and the text "Floors were not clean" should be automatically entered into the field: Cleanliness 1. The reason for this is that I wish to link the value from this field to a Microsoft Word document using mail merge for reporting purposes, and in the report it needs to state any problems in full sentences.



    I have tried using this code in order to update the comment field when the checkbox is ticked, however, the problem with this is that I would have to insert code manually for every single checkbox in my forms, and I have about 150 checkboxes in total.

    Code:
    Private Sub Cleanliness_A1_AfterUpdate()    If Cleanliness_A1.Value = -1 Then  'If checkbox is checked
          Cleanliness_C1.Value = Cleanliness_C1.DefaultValue
          Cleanliness_C1.Enabled = True
        Else
          Cleanliness_C1.Value = ""
          Cleanliness_C1.Enabled = False
        End If
    End Sub
    I would like to know, is there a better way to do this? I am still a newbie with regards to Access and Database design and structure, and I can't help but think there is a much better, more efficient way to accomplish this.

    Kind regards
    Nokoff

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,927
    First you should normalise your data - you should have a table with fields something like

    tblCleanliness
    CleanlinessPK text (e.g."C1") primary key
    AreaDesc text (e.g."Floors")

    then another

    tblQuestions
    QuestionPK autonumber
    BuildingFK long
    CleanlinessFK text (Child of CleanlinessPK in tblCleanliness
    CheckOK Boolean (default false)
    Comments text

    I've assume something to link this back to the building, business, whatever as BuildingFK

    then you would only need the one bit of code

    The only other way you can do this that I can think of is to create a public function in a module

    Code:
    Public Function Cleanliness_AfterUpdate()  
     If screen.activecontrol= -1 Then  'If checkbox is checked
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C"))= screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).DefaultValue
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).Enabled = True
        Else
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")) = ""
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).Enabled = False
        End If
    End Sub
    change the subformname to the name of your subform control

    then in your A1, A2 controls etc on afterupdate property put =Cleanliness_AfterUpdate() (i.e. i.e. replace the [Event Procedure]). You can do this by highlighting all the 'A' controls before typing this in.

  3. #3
    Nokoff is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    17
    Quote Originally Posted by Ajax View Post
    First you should normalise your data - you should have a table with fields something like

    tblCleanliness
    CleanlinessPK text (e.g."C1") primary key
    AreaDesc text (e.g."Floors")

    then another

    tblQuestions
    QuestionPK autonumber
    BuildingFK long
    CleanlinessFK text (Child of CleanlinessPK in tblCleanliness
    CheckOK Boolean (default false)
    Comments text

    I've assume something to link this back to the building, business, whatever as BuildingFK

    then you would only need the one bit of code

    The only other way you can do this that I can think of is to create a public function in a module

    Code:
    Public Function Cleanliness_AfterUpdate()  
     If screen.activecontrol= -1 Then  'If checkbox is checked
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C"))= screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).DefaultValue
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).Enabled = True
        Else
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")) = ""
          screen.activeform.subformname.form.controls(replace(screen.activecontrol,"A","C")).Enabled = False
        End If
    End Sub
    change the subformname to the name of your subform control

    then in your A1, A2 controls etc on afterupdate property put =Cleanliness_AfterUpdate() (i.e. i.e. replace the [Event Procedure]). You can do this by highlighting all the 'A' controls before typing this in.
    Thank you very much! I figured this out and adapted the code you gave me to work for my situation.

    However, now I would like to convert this to a web database, and I see that VBA is not supported for web databases. Is there any way to do this using macros instead? Or some other way?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I think macro equivalent would be SetValue action.

    You will probably be very frustrated by trying to filter records on those multiple Yes/No fields.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    I wonder if a non-existent problem isn't being solved here.

    If the checkbox Label is "Floors were not cleaned", the mere checking of that box records the fact that the floors were not cleaned ... why put those words into a comment field you'll need to clear out if the user realises they checked the box in error and un-checks it?

    To my mind that goes against all that normalisation seeks to achieve.

    I'd leave the comment field though, for things like 'Worse than ever'.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Agree this comment is redundant. And if user unchecks the checkbox, any comments, even their own input, still needs to be cleared.

    Again, non-normalized data structure possibly real issue. Instead of checkboxes, normalized structure would be a record in a related table for each observed condition. A 'checklist' may be fine for a paper document as a reference when doing 'walk through' but for relational database makes for poor data structure.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    I wonder if a better (normalised) way is to have -
    .tblEntities with fields lngID, strName, etc.
    .tblEntity_AuditExceptions with fields lngEntityID, intException, memComments
    .tblLookup_AuditExceptionCategories with fields bytID, strDescription
    .tblLookup_AuditExceptions with fields intID, bytCategory, and strDescription

    This would facilitate a radical un-complication of your form.

  8. #8
    Nokoff is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    17
    Quote Originally Posted by knarfreppep View Post
    I wonder if a non-existent problem isn't being solved here.

    If the checkbox Label is "Floors were not cleaned", the mere checking of that box records the fact that the floors were not cleaned ... why put those words into a comment field you'll need to clear out if the user realises they checked the box in error and un-checks it?

    To my mind that goes against all that normalisation seeks to achieve.

    I'd leave the comment field though, for things like 'Worse than ever'.
    Hey, thanks for taking the time to comment.

    The reason I'm using the comment field is so that I can transfer that text over to a mail merge word document report. I know it's a bit archaic but it's what is required.

  9. #9
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by June7 View Post
    A 'checklist' may be fine for a paper document as a reference when doing 'walk through' but for relational database makes for poor data structure.
    Absolutely ... of course, the paper/PDF/XLS 'checklist' can always, easily be produced from the normalised data.

  10. #10
    Nokoff is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    17
    That's interesting knarfreppep I'll have a look at that in the morning.

  11. #11
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by Nokoff View Post
    The reason I'm using the comment field is so that I can transfer that text over to a mail merge word document report. I know it's a bit archaic but it's what is required.
    Oh yes, I get what you want to do ... but the place to get that text from is tblLookup_AuditExceptions, where it will be stored only once in your dB but used many times with all the advantages that brings ... that's 'normalization'.

  12. #12
    Nokoff is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jul 2015
    Posts
    17
    What is the easiest way of getting the audit question text and audit exception text from the table fields without using VBA to populate the fields in my form?

  13. #13
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Use a query.

  14. #14
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    You would end up with a form and report looking not much more complicated than this -

    Audit Exceptions

    Entity XYZ Coy

    Category > Exception
    Cleanliness > Floors not cleaned Comment : Some areas OK
    Cleanliness > Door handles smudged
    Signage > Faded
    Signage > Out of date
    Tidyness > Waste paper baskets not emptied
    Uniforms > Creased

  15. #15
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106
    Quote Originally Posted by Nokoff View Post
    What is the easiest way of getting the audit question text and audit exception text from the table fields without using VBA to populate the fields in my form?
    Properly done, audit question text and audit exception text are the same thing save for the optional comment.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 05-16-2014, 07:26 AM
  2. Running code in function if checkbox is ticked
    By lewis1682 in forum Programming
    Replies: 7
    Last Post: 09-22-2013, 05:35 PM
  3. Replies: 4
    Last Post: 06-24-2013, 03:36 AM
  4. If Checkbox is ticked, Data Must be entered
    By DTK0902 in forum Access
    Replies: 8
    Last Post: 12-01-2012, 04:32 PM
  5. Open report if checkbox is ticked
    By Patience in forum Reports
    Replies: 3
    Last Post: 06-23-2010, 08:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums