Why when I dirty a subform does the default value of a control on the subform change?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanicaDear
    Contributor
    • Sep 2009
    • 269

    Why when I dirty a subform does the default value of a control on the subform change?

    I have a form (frmEmployees) with one control (Name) and on it is a subform (subHours) with 4 fields/controls where I can put some data, and one very important field (HoursName). HoursName is set to the default value of the only field on the main form.

    My desire is to scroll through our list of employees and enter hours for each one. The subform will contain all the data to save (the employees name and the hours each one worked). I have linked my master/child fields.

    The default value of HoursName is set as [Forms]![frmEmployees]![Name]. (I learned from experimenting ! does not equal . in this phrase.)

    Anyway, I thought I was having great success. When I open the form, the first employee's name shows up on the main form and in the subform. I enter the hours. It saves to the table. BAM!

    Then I use my arrows on my main form to scroll over to the next record, and the second employee name appears correctly on the main and subform. BUT when I dirty the form by typing into any field, the [HoursName] on my sub form changes from the name of the employee to "frmEmploye es". And it does this on every record afterwards.

    Can someone offer me any tips? (I have already played with different combinations of Enabled and Locked with no success.)

    Thanks in advance!!
    Last edited by zmbd; Sep 4 '13, 09:41 PM. Reason: [z{added some whitespace, easier on the old eyes :) }]
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    DanicaDear,
    What events have you programmed code to handle? When you say "It saves to the table. BAM!" I'm wondering if BAM! is right away, as in it is executing an "OnChange" event, or when you tab out of the field you edited ("AfterUpdat e" event) or when you click a save button or something else.

    Seems to me there may be some code we need to see.

    Jim

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      Name is a reserved keyword in Access, you should never use it as the name of a field, table, query, etc. While it won't stop you from using it, it will cause unpredicted behavior such as this. You may intend for it to pull the value of a control named name on your form, but instead it is pulling the property named name on your form. You need to rename everything that is using a reserved keyword.

      After doing this fix. You should be aware that you may not even need to set a default value for your HoursName field. If I understand what you have said, HoursName is your child field that is linked to the master field. In this setup, the value will be populated automatically due to master/child relationship, there's no need to populate it again.


      [Z{Edit- 20130904@14h43C }
      Access 2007 reserved words and symbols
      AllenBrowne- Problem names and reserved words in Access{/Edit}]
      Last edited by zmbd; Sep 4 '13, 09:43 PM. Reason: [z{added some links to reserved word/tokens to support Rabbit}]

      Comment

      • DanicaDear
        Contributor
        • Sep 2009
        • 269

        #4
        Jim,
        There is no code, at least none I have put in. I only say BAM because I have tried so many different things to make this simple thing work and so when I finally did get close I was just so excited.

        Rabbit,
        I think you may be on to something. I will apply your suggestions and report back. I initially didn't have the extra field because I too thought the data should populate from the first field. By when it did not I just figured I had screwed something up....yep.... LOL

        Thank you both so much. I love Bytes!!! Will report back soon.

        Comment

        • DanicaDear
          Contributor
          • Sep 2009
          • 269

          #5
          Yes, when I took out the "Name" reference everything worked. Ooohh that cost me some hours. LOL.

          Thanks so much!!

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            No problem! Good luck with the rest of your project.

            Comment

            Working...