Reflect Value of CheckBox in Field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Harry Boyes
    New Member
    • Dec 2011
    • 2

    Reflect Value of CheckBox in Field

    Hullo,

    I'm only contracted in where I'm working and I'm trying to strip a lot of the VBA out so the in-house development can make changes easier.

    I was wondering if I could set a control source on a checkbox and make the checkbox fill the control source depending on whether it is ticked or unticked?

    For example if there was a field "WantSandwi ch" and a checkbox next to a label saying "Do you want a sandwich?" connected to it then ideally when the user clicked the checkbox it would set the "WantSandwi ch" field to "Yes" and if it were unticked it would set it to "No"

    Regards,
    Harry

    P.S. I know this is a horrible way to do it and it should really be better laid out as a database, but this is all I have to work with
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    I don't get what your trying to say.
    For example if there was a checkbox for the field "WantSandwi ch" and a checkbox next to a label saying "Do you want a sandwich?" connected to it then ideally when the user clicked the tickbox it would set the "WantSandwi ch" field to "Yes" and if it were unticked it would set it to "No"
    Are you using 2 checkboxes to track the same thing here?

    Comment

    • Harry Boyes
      New Member
      • Dec 2011
      • 2

      #3
      Ah, sorry. Explained it badly.

      I meant to say:

      "For example if there was a field "WantSandwi ch" and a checkbox next to a label saying "Do you want a sandwich?" connected to it then ideally when the user clicked the checkbox it would set the "WantSandwi ch" field to "Yes" and if it were unticked it would set it to "No""
      Last edited by NeoPa; Dec 15 '11, 04:15 PM. Reason: Removed unnecessary quote

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        First off, lets try to get the definitions right, as it makes communication easier.

        A field is what you find in your table, your query or your recordset. It is also sometimes referred to as columns, but the most correct term is field. Examples could be ID_Person, tx_FirstName, tx_SurName, tx_PhoneNumber.

        A field cannot be next to a label. A control such as a textbox, a combobox, or a checkbox can be next to a label. A control can be unbound (Controlsource is empty) or bound (Controlsource lists the field to which it is bound) or calculated (The controlsource lists a calculation, such as "=[Price]*[Amount]")



        The following is all about bound forms (Form has a recordsource) and bound controls (see above)
        Now if you have a field WantSandwich, and the type of field is set to be a YES/NO field, with a default value of No (almost always remember default values in Yes/No fields), in your table, and you have pulled that field or the entire table into your form, and bound it to a checkbox by setting the checkboxes CONTROLSOURCE to be WantSandwich, then any click on that checkbox will change the value of the field WantSandwich in your table, for the currently selected record.

        I hope that makes sense.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          It certainly makes sense to me, and includes a lot of helpful explanations which are well worth taking note of.

          In case it's not as easy for the OP (Harry) to understand I'll just add that all you need to do in your situation is to include the name of the field from your table ([WantSandwich]) in the ControlSource property of your CheckBox. This will ensure all changes to the CheckBox are reflected in the related field.

          This is no different from what Smiley was saying. It simply expresses the same idea slightly differently.

          Comment

          Working...