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

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

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

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

Jim
Sep 4 '13 #2

Rabbit
Expert Mod 10K+
P: 12,365
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

100+
P: 256
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.
Sep 5 '13 #4

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

Thanks so much!!
Sep 9 '13 #5

Rabbit
Expert Mod 10K+
P: 12,365
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.