By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,892 Members | 710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,892 IT Pros & Developers. It's quick & easy.

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

P: 260
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 "frmEmployees". 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!!
Sep 4 '13 #1
Share this Question
Share on Google+
5 Replies

Expert 100+
P: 1,244
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 ("AfterUpdate" event) or when you click a save button or something else.

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

Sep 4 '13 #2

Expert Mod 10K+
P: 12,439
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}]
Sep 4 '13 #3

P: 260
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.

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.
Sep 5 '13 #4

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

Thanks so much!!
Sep 9 '13 #5

Expert Mod 10K+
P: 12,439
No problem! Good luck with the rest of your project.
Sep 9 '13 #6

Post your reply

Sign in to post your reply or Sign up for a free account.